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

2 comments

@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

21 Answered Questions

[SOLVED] Difference between proxy server and reverse proxy server

19 Answered Questions

[SOLVED] Getting git to work with a proxy server

2 Answered Questions

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

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

2 Answered Questions

2 Answered Questions

[SOLVED] Express - req.ip returns 127.0.0.1

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
  • 265 View
  • 0 Score
  • 1 Answer
  • Tags:   nginx proxy

1 Answered Questions

[SOLVED] Artifactory pro server behind an nginx frontend

1 Answered Questions

[SOLVED] Ngnix Jsession changed redirection issue

  • 2015-06-30 11:09:34
  • Crazy Developer
  • 413 View
  • 2 Score
  • 1 Answer
  • Tags:   nginx

2 Answered Questions

[SOLVED] nginx and trailing slash with proxy pass

Sponsored Content