NGINX 'global' location
Is it possible to create a 'global' location for an NGINX server? I'd like every site served by NGINX to have access to a /global/ folder; along the lines of
http {
[...stuff...]
#Global path
location /global/ {
root /my/global/location/;
}
server {
listen 127.0.0.1:80;
server_name example.com;
[...standard config...]
}
server {
listen 127.0.0.1:80;
server_name example.org;
[...standard config...]
}
server {
listen 127.0.0.1:80;
server_name example.net;
[...standard config...]
}
}
And be able to access files in the global location from http://example.com/global/ http://example.org/global/ etc.
I can do this if I add the global location block to every server
block but that's annoying, I'd like to have it defined globally and be able to access it from within the sites.
I could use an include
directive in each host, but it still requires specification in each host. The NGINX wiki says the 'location' block is only valid within the server
context but I didn't know if there was a rewrite trick or something similar.
It's not no and as far as I know there isn't any talk of changing that either.
What about just include it? e.g.
include /etc/nginx/global-location.conf;
I know you need to add it to each of the vhosts but it allows to do further changes easily and I think it is faster than having dynamic vhosts.
You can sort of do it the other way round, by using dynamic vhost directories.
for example:
server {
...
server_name ~^(www\.)?(?<domain>.+)$;
...
location /global/ {
root /my/global/location/;
}
...