I am wanting to use multiple files declared at
/etc/nging/sites-available/
symlinked to:
/etc/nginx/sites-enabled/
Now the files look similar to below – call this team1.conf:
server {
listen 80;
location /team1/app3/location/region {
rewrite ^/team1/app3/location/region(.*) /path3/healthcheck$1 break;
proxy_pass https://this.is.the.backend.app.example;
}
location /team1/app4/location/region {
rewrite ^/team1/app4/location/region(.*) /path4/healthcheck$1 break;
proxy_pass https://this.is.the.backend.app.example;
}
location /team1/app5/location/region {
rewrite ^/team1/app5/location/region(.*) /path5/healthcheck$1 break;
proxy_pass https://this.is.the.backend.app.example;
}
}
Call this team2.conf:
server {
listen 80;
location /team2/app3/location/region {
rewrite ^/team2/app3/location/region(.*) /path3/healthcheck$1 break;
proxy_pass https://this.is.the.backend.app.example;
}
location /team2/app4/location/region {
rewrite ^/team2/app4/location/region(.*) /path4/healthcheck$1 break;
proxy_pass https://this.is.the.backend.app.example;
}
location /team2/app5/location/region {
rewrite ^/team2/app5/location/region(.*) /path5/healthcheck$1 break;
proxy_pass https://this.is.the.backend.app.example;
}
}
I wanted to keep them separate – hence the separate files – however, with two files, nginx just seems to read the first one and 404 anything in the second one – so I suspect there is a conflict somewhere….
The files are pretty arbitrary – I just wanted to demonstrate – the paths etc, will vary between files..
Any help would be great – apologies if I’ve missed something obvious..
Cheers
2
Answers
Thats great - this is all teaching me a lot! so thanks for that!
I have gone with the following structure:
within
/etc/nginx/conf.d/main.conf
:Then within
/etc/nginx/shared/
:I have both files:
team1.conf
:team2.conf
:This seems to work ok - hopefully this is an accepted way of structuring it. @IvanShatsky
Too long for a comment, so I’m writing this as an answer.
Check your main
/etc/nginx/nginx.conf
configuration. I think something likeis present there. Notice that those files are included under the
http
context. So you can use whatever you want, but not the/etc/nginx/conf.d/*.conf
or any file inside thesites-enabled
directory. Something like/etc/nginx/shared/...
will be ok, I think. I don’t use thosesites-available
/sites-enabled
directories at all in favor ofconf.d
directory – read the Difference in sites-available vs sites-enabled vs conf.d directories (Nginx)? discussion on ServerFault.You can have any number of
server
blocks listening the same port. Nginx will choose the right block according to the HTTPHost
header value. If it isn’t match any of the defined server names in any server block (or theHost
header is missing at all from the request), the default server will be used to serve it. See the How nginx processes a request official documentation page or this answer for even more details.