Reputation: 83
I'm trying to set nginx location that will handle various paths and proxy them to my webapp.
Here is my conf:
server { listen 80; server_name www.example.org; #this works fine location / { proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://localhost:8081/myApp/; } #not working location ~ ^/(.+)$ { proxy_pass http://localhost:8081/myApp/$1; } }
I would like to access myApp with various paths like: /myApp/ABC, /myApp/DEF, myApp/GEH or /myApp/ZZZ. Of course these paths are not available in myApp. I want them to point to root of myApp and keep url. Is that possible to archive with nginx ?
Upvotes: 4
Views: 1994
Reputation: 48
You will probably have to do a rewrite followed by a proxy pass, I had the same issue. Check here: How to make a conditional proxy_pass within NGINX
Upvotes: 1
Reputation: 4756
A very late reply. this might help someone
try proxy_pass /myApp/ /location1 /location2;
Each location separated with space.
Upvotes: 1
Reputation: 12521
Nginx locations match in order of definition. location /
is basically a wildcard location, so it will match everything, and nothing will reach the second location. Reverse the order of the two definitions, and it should work. But actually, now that I look at it more closely, I think both locations are essentially doing the same thing:
/whatever/path/ ->>proxies-to->> http://localhost:8081/myApp/whatever/path/
Upvotes: 2