D
D
DmitryRise2018-07-19 14:29:16
Django
DmitryRise, 2018-07-19 14:29:16

Django + Nginx why configuration gives hell when indexed by search engines?

Hello, I have a strange problem. There are ten Django sites on the gunicorn + Nginx daemons on the server.
The problem is that after the new site was placed, it began to be indexed under the addresses of other projects. For example.
The new site on the server has the domain name www.1.ru and the title "Site 1"
The following content appears in the search engine
: www.2.ru Site 1
www.3.ru Site 1 404 Nginx configuration
crashes when going to these addresses

server {
    server_name www.domain.ru domain.ru;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/domain/domain/;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/domain/domain/domain.sock;
    }

    gzip on;
    gzip_disable "msie6";
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;



    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/domain.ru/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/domain.ru/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    if ($host = domain.ru) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = www.domain.ru) {
        return 301 https://domain.ru;
    }
    server_name www.domain.ru domain.ru;
    listen 80;
    return 404; # managed by Certbot
}

Tell me, please, what could be the problem?
Found out that in the project settings ALLOWED_HOSTS was empty, but I doubt that this can affect such an issue

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Kopitsa, 2018-07-19
@DmitryRise

add a default server for nginx with a stub, then all requests will go to it.
https://nginx.ru/ru/docs/http/request_processing.html

server {
    listen      80 default_server;
    server_name example.net www.example.net;
    ...
}

Without this, all requests go to the first specified server for the given ip/port, which is django.
Plus, the janga itself had header validation disabled (ALLOWED_HOSTS is empty).
I recommend setting up on nginx, it is much cheaper in terms of resources.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question