nginx - Working with alias inside location -
so here's server block
server { listen 80; server_name domain.tld; root /var/www/domain.tld/html; index index.php index.html index.htm; location / { } location /phpmyadmin { alias /var/www/phpmyadmin; } location /nginx_status { stub_status on; access_log off; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param script_filename $document_root$fastcgi_script_name; include fastcgi_params; } }
browsing http://domain.tld/index.php works fine problem im encountering browsing http://domain.tld/phpmyadmin/. returns 404 yet folder /var/www/phpmyadmin exist on server. viewing /var/log/nginx/error.log, no error being logged there yet access logged in /var/log/nginx/access.log. problem here?
the problem phpmyadmin php application , location ~ \.php$
block not point correct document root.
you need construct 2 php locations different document roots.
if phpmyadmin located @ /var/www/phpmyadmin
, not need alias
directive, root
directive more efficient. see this document.
server { listen 80; server_name domain.tld; root /var/www/domain.tld/html; index index.php index.html index.htm; location / { } location /nginx_status { stub_status on; access_log off; } location ~ \.php$ { try_files $uri =404; include fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_param script_filename $document_root$fastcgi_script_name; } location ^~ /phpmyadmin { root /var/www; location ~ \.php$ { try_files $uri =404; include fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_param script_filename $document_root$fastcgi_script_name; } } }
the location ^~ /phpmyadmin
prefix location takes precedence on regex location used process .php
files. contains location ~ \.php$
block inherits value of /var/www
document root.
it advisable include fastcgi_params
before defining other fastcgi_param
parameters otherwise custom values may silently overwritten.
see this document more.