Nginx proxy pass without the location url on proxy_pass

Viewed 1003

I am trying to proxy pass in nginx. here is what the config looks like :

location /amazon {
        proxy_pass http://amazon.com;
    }

when I open domain.com/amazon it takes me to amazon.com/amazon. How should I write it so that is opens only amazon.com, without /amazon.

1 Answers

You can rewrite the URL to cut the /amazon prefix. Example:

location /amazon/ {
  rewrite /amazon/(.*) /$1 break;
  proxy_pass https://www.amazon.com;

  # bonus configuration for this particular host
  # may be irrelevant in your case
  proxy_set_header Host "www.amazon.com";
  proxy_ssl_server_name on;
}
Related