1

The following proxy works elegantly resolving http://my.org/ to the proxied address:

location / { proxy_pass http://127.0.0.1:8082; } 

However, adding a name in the URI breaks things and results in a 404 error:

location /luigi/ { proxy_pass http://127.0.0.1:8082; } 

Also tried rewriting but to no avail:

location /luigi/ { rewrite ^/luigi/(.*)$ /$1 break; proxy_pass http://127.0.0.1:8082; } 

accesss.log:

myip - - [24/Jul/2020:16:56:36 -0400] "GET /luigi/ HTTP/1.1" 404 513 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" "-" myip - - [24/Jul/2020:16:56:36 -0400] "GET /error?src=404&ifr=1&error= HTTP/1.1" 404 153 "http://myurl/luigi/" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" "-" myip - - [24/Jul/2020:16:56:47 -0400] "GET /luigi/ HTTP/1.1" 404 513 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" "-" myip - - [24/Jul/2020:16:56:47 -0400] "GET /error?src=404&ifr=1&error= HTTP/1.1" 404 153 "http://myurl/luigi/" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" "-" 

error.log:

2020/07/24 16:56:32 [notice] 107788#0: signal process started 2020/07/24 16:56:36 [error] 107789#0: *13 open() "/usr/share/nginx/html/error" failed (2: No such file or directory), client: myip, server: , request: "GET /error?src=404&ifr=1&error= HTTP/1.1", host: "myurl", referrer: "http://myurl/luigi/" 2020/07/24 16:56:47 [error] 107789#0: *13 open() "/usr/share/nginx/html/error" failed (2: No such file or directory), client: myip, server: , request: "GET /error?src=404&ifr=1&error= HTTP/1.1", host: "myurl", referrer: "http://myurl/luigi/" 

Can anybody please help?

3
  • Hi tash, it could already help to add an '=' to the location, e.g. ' location = /luigi/ '. Should you run non-static content behind that location you might consider a ' location ~* ^/luigi/(.*)$ '. Some Nginx pros will probably correct me :). Cheers Commented Jul 24, 2020 at 21:59
  • What are you trying to do exactly? Expose /luigi app in the browser as an / (root) or /luigi on the backend server? Which one? Commented Jul 24, 2020 at 22:30
  • Hi @Toumash, I need to set up multiple proxy_pass against one public url. The first configuration I provided displays the Luigi server against http://my.org. However, when I have many of them such as Luigi, Dash, and a static html, I need a string in the URL that would differentiate among the above three. Hence the string /luigi comes. I think my answer to your question would be "expose /luigi app in the browser". Commented Jul 25, 2020 at 2:14

1 Answer 1

1

You can try the following:

location ~ /luigi/(.*) { proxy_pass http://127.0.0.1:8082/$1; } 

This will capture the path after /luigi to a variable, and add the path to proxy_pass path.

You need to make sure that your application generates proper URLs in the links it creates. Often it is a problem that the application generates URLs like http://127.0.0.1:8082 and one cannot set it up to generate proper URLs in reverse proxy configuration.

7
  • Hi @Tero, doing the above didn't help. Upon doing that, when I plug in http://my.org/luigi/, the URL gets rewritten as http://pnl_servers.dipr.partners.org/static/visualiser/index.html, yet I get 404. However, for my very first block, without any name after /, the URL gets rewritten as http://pnl_servers.dipr.partners.org/static/visualiser/index.html# (note the trailing #). Commented Jul 25, 2020 at 17:14
  • I think you are right about and one cannot set it up to generate proper URLs. In the process of rewriting and responding back to the original URL, there is a problem that hinders nginx to serve back. Commented Jul 25, 2020 at 17:15
  • Yes, it seems that the app is sending back a redirect to some other domain (perhaps the domain it is configured to use). Commented Jul 25, 2020 at 17:19
  • Then use the Host header stackoverflow.com/a/14352958/3711660 Commented Jul 28, 2020 at 8:28
  • Hi @Toumash, I tried the following: ``` location /luigi { proxy_pass 127.0.0.1:8082; proxy_set_header Host $http_host; } ``` yet again, the url http://my.org/luigi gets rewritten as http://my.org/static/visualiser/index.html and results in error404. While I don't know if I followed your suggestion right, any other bright idea? Commented Jul 28, 2020 at 13:40

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.