E
E
Eugene2016-02-21 17:18:58
Django
Eugene, 2016-02-21 17:18:58

Implementation: nginx + gunicorn + django. How to remove a redirect from domain to domain?

Good afternoon. I deal with dzhanga and try to roll out the project to production. I use nginx + gunicorn.
The essence of the problem. Two domains are delegated to the server: t-wave.ru and dragonesis.xyz. When visiting t-wave.ru, everything seems to be fine. But dragonesis.xyz somehow redirects to t-wave.ru
Configs for nginx in the sites-available
t-wave.ru folder

server {
    listen 80;
    server_name  www.t-wave.ru;
    rewrite ^/(.*) http://t-wave.ru/$1 permanent;
}


server {
    listen 80;
    server_name t-wave.ru;
    keepalive_timeout 3;
    access_log off;
    error_log /opt/myenv/log/nginx_error.log crit; 

    location / {
        proxy_pass http://127.0.0.1:8000; 
        proxy_set_header Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /static/ {
        alias /opt/myenv/myproject/static/;
        expires 3d;
    }

    location /media/ {
        alias /opt/myenv/myproject/media/;
           expires 3d;
    }

    location ~* \.(7z|jpg|jpeg|gif|png|ico|css|bmp|swf|js|html|txt|doc|docx|pdf|rar|xls|xlsx|zip)$ {
        root /opt/myenv/myproject/;
        expires 3d;
        add_header Cache-Control: public;
        access_log off;
        error_log /opt/myenv/log/nginx_static_error.log;
    }
}

dragonesis.xyz
server {
    listen 80;
    server_name  www.dragonesis.xyz;
    rewrite ^/(.*) http://dragonesis.xyz/$1 permanent;
}


server {
    listen 80;
    server_name dragonesis.xyz;
    keepalive_timeout 3;
    access_log off;
    error_log off; 

    location / {
        proxy_pass http://127.0.0.1:8001; 
        proxy_set_header Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /static/ {
        alias /opt/dragonesis.xyz/static/;
        expires 3d;
    }

    location /media/ {
        alias /opt/dragonesis.xyz/media/;
           expires 3d;
    }

    location ~* \.(7z|jpg|jpeg|gif|png|ico|css|bmp|swf|js|html|txt|doc|docx|pdf|rar|xls|xlsx|zip)$ {
        root /opt/dragonesis.xyz/;
        expires 3d;
        add_header Cache-Control: public;
        access_log off;
        error_log /opt/dragonesis.xyz/log/nginx_static_error.log;
    }
}

For t-wave.ru and dragonesis.xyz they are similar, they differ only in paths and port (*:800*). At the same time, dragonesis.xyz is not a Dzhang application and gunicorn with supervisor, in theory, should only work with the t-wave.ru domain Supervisor config
for t-wave.ru
[program:myproject]
command=/opt/myenv/bin/gunicorn myproject.wsgi:application -c /opt/myenv/myproject/myproject/gunicorn.conf.py

umask=022
autostart=true
autorestart=true
startsecs=10
startretries=3
exitcodes=0,2
stopsignal=TERM
stopwaitsecs=10
user=nobody

gunicorn.conf.py
bind = '127.0.0.1:8000'
workers = 3
user = "nobody"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AntonMZ, 2016-02-21
@dragonesis

t-wave.ru/:
It worked!
Congratulations on your first Django-powered page.
dragonesis.xyz/:
502 Bad Gateway
What should be served on the second site?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question