AnswerBun.com

nginx proxy_pass with uri not working

Server Fault Asked on January 5, 2022

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?

One Answer

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.

Answered by Tero Kilkanen on January 5, 2022

Add your own answers!

Related Questions

How to install company proxy certificate

1  Asked on January 9, 2021 by chandima-jayawickrema

       

Windows server 2019 RRAS slow download speed

0  Asked on January 9, 2021 by selfishcrawler

     

Allow download of pdf files only in .htacces file

0  Asked on January 9, 2021 by user2033464

   

Freeradius LDAP through AP

1  Asked on January 9, 2021 by smok

     

NFS access from multiple networks

1  Asked on January 7, 2021

   

Nginx+gunicorn 404

1  Asked on January 6, 2021 by vassily

   

Docker swarm, all containers get restarted

1  Asked on January 6, 2021 by saabeilin

   

Error when update Sugarcrm CE via Admin->Upgrade

0  Asked on January 5, 2021 by ashish-kumar-dubeyitho-noidain

     

Is deploying .NET Framework 3.5 possible in WSUS?

4  Asked on January 5, 2021 by thecleaner

     

How to know if the server application is listening on ipv6

2  Asked on January 5, 2021 by lapinkoira

         

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP