Search code examples
macosnginxproxyproxypass

How to preserve request url with nginx proxy_pass on Mac OSX


I've follow the instructions asked here, but it still changes the request url for both 80 and 443 server, does anybody have the same issue?

I'am using the OS X El Capitan 10.11.4, and I use the same nginx.conf and it works perfectly and preserves the request url on Ubuntu 12.04.5 LTS.

Below is my proxy setting.

location / {
    proxy_pass   http://my_app_upstream/;
    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;
    proxy_set_header        Host            $host;
}

for the installation I use brew install nginx on Mac and self-compiled one on Ubuntu


Solution

  • If you don't want the URL to change (e.g., due to Nginx pass_proxy subdirectory without url decoding), you should omit the trailing slash from your proxy_pass:

    -proxy_pass   http://my_app_upstream/;
    +proxy_pass   http://my_app_upstream;