0

Please help, I am trying to proxy pass my domain.com/travel to a node app that has the content running here 255.255.255.255:1234/travel ... How do I do this?

I currently have this:

location /travel/ {
    rewrite ^/travel(/.*)$ $1 break;
    proxy_pass  http://255.255.255.255:1234/travel;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

This partially works but it goes to the root of the application in http://255.255.255.255:1234 instead. I was able to do this in Apache with this

ProxyPreserveHost On
ProxyPass /travel/ http://255.255.255.255:1234/travel/
ProxyPassReverse /travel/ http://255.255.255.255:1234/travel/
ProxyPass /travel http://255.255.255.255:1234/travel/
ProxyPassReverse /travel http://255.255.255.255:1234/travel/

but since moving to Nginx I cannot replicate this. Help?

Neo Ighodaro
  • 109
  • 1
  • 1
  • 3

1 Answers1

2

You should be able to use this:

location /travel(/.*)$ {
    rewrite ^ $1 break;
    proxy_pass  http://example.com:1234/travel$1;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

I moved the regex capture to the location directive, although that doesn't make a big difference. Then, I added the $1 to the end of proxy_pass, so that the proxy_pass destination URL gets the regex capture results appended to end of the URL.

Tero Kilkanen
  • 34,499
  • 3
  • 38
  • 58