According to nginx documentation, location cannot be used inside http
block. This means that you have to add locations for every virtualhost. However you can save your bunch of layouts into a separate file and include it with include
command. Here is an example for a generic virtualhost:
server {
listen 80;
root /var/www/nginx-default;
include /etc/nginx/global.d/*.conf;
}
And you write all global locations in a separate *.conf
files under /etc/nginx/global.d
. Your code may be placed in /etc/nginx/global.d/phpmyadmin.conf
, for example.
Update: As for your PHPMyAdmin locations: instead of aliasing every file you should pass SCRIPT_FILENAME variable in the following way:
location ~ ^/phpmyadmin/(.+\.php)$ {
include fcgi.conf;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_param SCRIPT_FILENAME /home/phpmyadmin$fastcgi_script_name;
}
Note that you need to use /home/phpmyadmin
instead of $document_root
because alias directive does not change document root. This means that for my generic virtualhost (as above) requesting URL http://localhost/phpmyadmin/test.php
will try to execute /var/www/nginx-default/phpmyadmin/test.php
which is not the expected behaviour.