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


[server 1] <-|-> [server 2]
[Apache]   <-|-> [nginx <--> gunicorn <--> django]

Apache is running on a server 1 which silently redirects just one subdomain to server 2. For some reason nginx returns 301 moved permanently and redirects to the real IP of the server 2.

Server 1 config - Apache

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$
RewriteRule (.*) http://123.456.789.000/$1 [P,L]

Server 2 config - nginx

server {
  listen   80;
  # I put the '' name here while trying to fix the issue.
  server_name 123.456.789.000;

  location / {
      proxy_pass_header Server;
      proxy_set_header Host $host;
      proxy_redirect off;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Scheme $scheme;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_connect_timeout 10;
      proxy_read_timeout 10;
      proxy_pass http://localhost:8000/;

I am sure there is something wrong with the proxy configuration in nginx which is set up to handle gunicorn. Unfortunately I am not experienced enough to know which headers cause that. Also I don't really know what is the difference between X-Real-IP and X-Forwarded-For.


Static files handled by this location in the above server block are accessed just fine from the server 1 domain, without redirection to the local ip of the server 2.

  location /static {
    autoindex on;
    alias /var/www/django/static;
share|improve this question
Are you sure there's no other active config that nginx is using, for example in /etc/nginx/conf.d? – Flup Apr 9 '14 at 12:47
No. There used to be a symlink to the default site in sites-enabled but I disabled everything not related to my site. Only other entries in the config file not added here are unrelated like keepalive_timeout 65;. I added a location block for the static files which are handled fine to the question. – ficiek Apr 9 '14 at 12:59

Your Answer


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

Browse other questions tagged or ask your own question.