Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Description:

[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 'subdomain.domain.com' name here while trying to fix the issue.
  server_name subdomain.domain.com 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.

edit:

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 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 at 12:59

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.