I can't seem to find the equivalent of Apache's ProxyPreserveHost http://httpd.apache.org/docs/2.0/mod/mod_proxy.html#proxypreservehost option in nginx. This is required to reverse proxy to virtual hosts.

What it does is replace the host name the browser provides with the host name of the downstream server.

Does it exist?

2 Answers 2


I think I found a solution to the problem. Sending the downstream server's host is the default behavior in nginx, and I had overridden it by using the directive:

proxy_set_header Host $host;

Which sends the host requested by the browser to the downstream server. Exactly the opposite of what I wanted.

So while nginx doesn't have an equivalent to Apache's ProxyPreserveHost, the same behavior can be achieved with the proxy_set_header directive, and nginx's solution is more general.

  • 1
    Should be proxy_set_header Host $http_host;.
    – Rob
    Jan 2, 2017 at 10:39
  • @Rob, $http_host doesn't exist according to Nginx docs: nginx.org/en/docs/varindex.html Jul 31, 2018 at 17:50
  • 1
    @DanielSerodio Actually, yes it does exist, at least for 99.99% of connections. See the documentation. It also differs very subtly from $host. Jul 31, 2018 at 18:35
  • @MichaelHampton I stand corrected, thanks for the link Jul 31, 2018 at 20:23

A working example:

  set $s3_bucket 'SOMEBUCKET.s3.amazonaws.com';

  location / {
        send_timeout 5m;
        proxy_read_timeout 240;
        proxy_send_timeout 240;
        proxy_connect_timeout 240;
        proxy_http_version 1.1;
        proxy_set_header Host $s3_bucket;
        proxy_set_header Authorization '';
        proxy_hide_header x-amz-id-2;
        proxy_hide_header x-amz-request-id;
        proxy_ignore_headers "Set-Cookie";
        proxy_buffering off;
        proxy_intercept_errors on;
        proxy_redirect off;
        proxy_pass http://$s3_bucket;
  • This is using nginx.
    – cod3fr3ak
    Aug 16, 2013 at 3:59

You must log in to answer this question.