Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can't seem to find the equivalent of Apache's 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?

share|improve this question

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 command:

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 command, and nginx's solution is more general.

share|improve this answer

A working example:

  set $s3_bucket '';

  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;
share|improve this answer
This is using nginx. – cod3fr3ak Aug 16 '13 at 3:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.