I've got a site called http://example.com
, with an app running that can be accessed at http://example.com/app1
. The app1 is sitting behind an nginx reverse proxy, like so:
location /app1/ {
proxy_pass http://localhost:8080/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
Adding the trailing slash to the proxy_pass
field lets me "remove" the /app1/ part of the URL, at least as far as the app is concerned. So app1 thinks that it's getting requests to the root url (as in, I have a route in app1 that sits on '/'
, not '/app1'
).
However, I'd like to have nginx make this case-insensitive. So whether I go to http://example.com/App1
or http://example.com/APP1
, it should still just forward the request to app1, and remove the /app1/ part of the url.
When I attempt to use nginx's case insensitive rules, it does not let forward the rest of the URI to app1.
location ~* /app1/ {
proxy_pass http://localhost:8080/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
That gives me an nginx configuration error.
My goals are two fold:
/app1/
case insensitively /app1/
part of the url when "passing" the url over to the appI've tried rewriting the url, but it won't let me add the rest of the URI to proxy_pass.
Any help would be appreciated!
You should capture rest of the url and then use it
location ~* /app1/(.*) {
proxy_pass http://localhost:8080/$1$is_args$args;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With