By elzix88

2014-10-22 18:16:44 8 Comments

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;

    #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 ?


@Sibiraj 2017-04-21 01:25:10

A very late reply. this might help someone

try proxy_pass /myApp/ /location1 /location2;

Each location separated with space.

@David Eyk 2015-02-04 21:21:07

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/

Related Questions

Sponsored Content

19 Answered Questions

[SOLVED] Getting Git to work with a proxy server - fails with "Request timed out"

19 Answered Questions

2 Answered Questions

Keycloak Redirect url with nginx is going to http rather than https

  • 2018-04-03 12:02:15
  • Atulya Nair
  • 1543 View
  • 4 Score
  • 2 Answer
  • Tags:   nginx jboss

2 Answered Questions

2 Answered Questions

[SOLVED] Express - req.ip returns

1 Answered Questions

[SOLVED] How to use NGINX as forward proxy for any requested location?

1 Answered Questions

Nginx win server 2012 - Configure proxy pass

  • 2017-07-31 15:02:09
  • johns193
  • 338 View
  • 0 Score
  • 1 Answer
  • Tags:   nginx proxy

1 Answered Questions

[SOLVED] Ngnix Jsession changed redirection issue

  • 2015-06-30 11:09:34
  • Mukesh Kumar
  • 492 View
  • 2 Score
  • 1 Answer
  • Tags:   nginx

2 Answered Questions

[SOLVED] nginx and trailing slash with proxy pass

Sponsored Content