So I'm using Nginx as a reverse proxy, and my current config has gotten very long, since I have about 12 sub-domain's, and that number will continue to grow a little more. I'm looking for a way to clean up my config, and I think I found a way but I can't get it to work. Here is what I'm trying:
server {
server_name ~^(.+)\.domain\.com$;
ssl on;
location ~ domain1 {
proxy_pass http://192.168.1.50:4040/;
}
location ~ domain2 {
proxy_pass http://192.168.1.60:4040/;
}
}
But it's giving me an error that says
nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except"
And I understand what it's saying, but unsure how to resolve it. If I remove the trailing slash from the proxy_pass
directives, Nginx will start without error but neither of the subdomains work.
Am I going about this the right way? Is there a better way to do it?
Thanks in advance!
server
blocks for eachserver_name
?server
blocks, but as I said, my config is growing quite large. I have to scroll to to see all the config to verify everything is there, and it's annoying to me. I could do separate conf files, but again, I'd have to open each of them to verify configs (some haveauth_basic
, others have differentproxy_pass
params, etc). I'm literally hoping I can shrink my config to where I can see it all easier.