首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nginx顶级域名重定向至子域名

nginx顶级域名重定向至子域名
EN

Stack Overflow用户
提问于 2019-02-22 05:33:43
回答 1查看 149关注 0票数 0

我的nginx配置将所有请求从domain.ru重定向到subdomain.domain.ru,我不知道为什么。下面是我的配置:

代码语言:javascript
复制
    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运行在一个暴露端口80到端口8000的容器中。没有提到"domain.ru",为什么它还在提供它?

添加:事实上它响应任何具有永久重定向的子域:

代码语言:javascript
复制
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/
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-22 05:49:16

因为您的nginx是为subdomain.domain.ru配置的。

domain.ru的请求落地到subdomain.domain.ru中,它肯定有足够的代码重定向到规范的http://subdomain.domain.ru/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54816576

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档