I have my nginx as a reverse proxy set up like this:
server {
listen 80;
server_name mydomain.com anotherdomain.es 20.18.4.140;
location ^~ /service/ {
proxy_pass http://20.18.4.146/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ^~ /vm2/ {
proxy_pass http://20.18.4.146/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ^~ /vm3/ {
proxy_pass http://20.18.4.142:6001/;
#proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto $scheme;
} location / {
proxy_pass http://20.18.4.148/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
} }
server {
listen 443 ssl;
server_name mydomain.com anotherdomain.es 20.18.4.140;
fastcgi_param HTTPS on;
include /etc/nginx/include/ssl;
location ^~ /service/ {
proxy_pass https://20.18.4.146/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ^~ /vm2/ {
proxy_pass https://20.18.4.146/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ^~ /vm3/ {
proxy_pass https://20.18.4.142:6000/;
#proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
proxy_pass https://20.18.4.148/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Now I'm accessing it correctly this way:
mydomain.com/service/... anotherdomain.es/service/...
mydomain.com/vm2/... anotherdomain.es/vm2/...
mydomain.com/vm3/... anotherdomain.es/vm3/...
mydomain.com/... anotherdomain.es/...
Redirects all traffic from a location to the appropriate server. The rest of the url (including the parameters) are unproblematic and have upper and lower case.
But I would need the locations to be case insensitive. And to be able to access it like that (or any other combination):
mydomain.com/Service/... anotherdomain.es/SERVICE/...
mydomain.com/VM2/... anotherdomain.es/Vm2/...
I don't want to repeat the locations or repeat the configuration of each one. I would like to do it better and more efficiently.
I have tried with regular Expressions but checking the syntax gives me errors and it doesn't work. For example this one:
~* ^/(vm2|Vm2|VM2)/$
~* ^/vm2/
~* /(<vm2>/g)
~* /app1/(.*)
...
Error:
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" block in /etc/nginx/sites-enabled/my-sites:4 nginx: configuration file /etc/nginx/nginx.conf test failed
And also it could be the case: mydomain.com/vm2/service/15 (being regular expressions it would be 2)
I've looked and tried a lot but I don't see anything that works for me. Any ideas? Thanks.