0

Disclaimer:

I have opened a similar question of stack overflow before realize that stack overflow is mean to code questions...

My problem:

I am trying to access a a web service connected to my nginx server over a ssh tunnel. It works perfectly if I ssh the server, and curl the tunnel port. My next step would be to do a proxy_pass on my nginx configuration to allow us to access that service given the port. I tough I had nailed it using the following configuration:

location ~ ^/test/([0-9]+)/ {
    #allow our.ip/32;
    proxy_pass http://127.0.0.1:$1/;
}

When the index load, it try to redirect to a page named login.php (which exists, and I can reach it by using curl localhost:port/login.php). After some research, I came up with the solution of remove the slashes from both the location and proxy_pass, making it look like this:

location ~ ^/test/([0-9]+) {
    #allow our.ip/32;
    proxy_pass http://127.0.0.1:$1;
}

This is pretty much what you find in most of the examples, BUT IT DON'T WORK. It just 502 and I can't figure out why.

EDIT

This is the nginx error log from the request:

2021/01/11 14:21:49 [error] 88542#88542: *19093 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: my.server.address, request: "GET /test/1480/ HTTP/2.0", upstream: "http://127.0.0.1:1480/test/1480/", host: "my.server.address"

It should not pass the "/test/" to the remote host...

  • Hi! When your index page make redirect to login.php, your browser send "GET /login.php" to your nginx and it doesn't match your location ~ ^/test/([0-9]+). Or your mean /test/index.php ? Or you want to remove 'test/PORT" from request to upstream, or you have other locations in your config? Please provide nginx error log and full nginx config if it's possible. – Alexander Makarenko Jan 11 '21 at 16:33
  • Hey @AlexanderMakarenko I did not mean to access "remotehost/test/index.php", just "remotehost/index.php". I also included the error in my question. Do I need to post the entire nginx config? – Guilherme Richter Jan 11 '21 at 17:32

0 Answers0