简体   繁体   中英

nginx top-domain redirects to subdomain

My nginx configuration redirects all requests from domain.ru to subdomain.domain.ru and I don't understand why. Here is my configuration:

    upstream upstream_server {
      server unix:/sockets/inst_site.sock fail_timeout=60s;
    }


server {
        listen 8000;
        server_name www.subdomain.domain.ru;
        return 301 $scheme://subdomain.domain.ru$request_uri;
}

server {
    listen 8000;
    server_name subdomain.domain.ru;
    #index index.html;

    location /static/ {
        autoindex off;
        root "/project/inst_site/";

        if (!-e /project/inst_site$uri) {
            rewrite    ^/static(.*)$    /static-root$1;
        }
    }

    location /static-root/ {
        autoindex off;
        root "/project/inst_site/";
    }

    location / {
        proxy_redirect          off;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout   90;
        proxy_send_timeout      90;
        proxy_read_timeout      90;
        proxy_buffers           32 4k;

            location /graphql/ {
                proxy_set_header Host localhost;
                proxy_pass http://upstream_server;
            }

            location /admin/ {
                proxy_set_header Host localhost;
                proxy_pass http://upstream_server;
            }

            autoindex off;
            root "/project/inst-ng/dist/inst-ng";
            try_files $uri $uri/ index.html;

    }
}

Nginx runs in a container exposing port 80 to port 8000. There is no mention of "domain.ru", why it still serves it?

ADDED: In fact it response to any subdomain with permanent redirect:

curl --head http://nhnhnhnhnh.domain.ru
HTTP/1.1 301 Moved Permanently
Server: nginx/1.15.8
Date: Thu, 21 Feb 2019 21:37:57 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: http://subdomain.domain.ru/

Because your nginx is configured for subdomain.domain.ru .

Request to domain.ru lands into subdomain.domain.ru 's, which surely enough has code to redirect to canonical URL which is http://subdomain.domain.ru/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM