【问题标题】:nginx not stripping www using rewritenginx不使用重写剥离www
【发布时间】:2015-04-21 13:39:25
【问题描述】:

我想在我的 nginx 配置中从我的 url 中删除 www 并查看文档和堆栈溢出帖子,我编写了以下配置,但它似乎不起作用。

server_name {
          server_name www.subdomain.domain.com;
          rewrite ^(.*) https://subdomain.domain.com/$1 permanent
        }
server_name {
            server_name subdomain.domain.com;

            listen 80 default_server;
            listen [::]:80 default_server ipv6only=on;

            root /file;
            index index.html index.htm app.js;

            location /{

                   proxy_pass https://subdomain.domain.com:443/;
                   proxy_redirect off;
                   proxy_set_header Host $host;
                   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            }
            location /*/ {
                   proxy_pass https://subdomain.domain.com:443/;
                   proxy_redirect off;
                   proxy_set_header Host $host;
                   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            }

        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        #location /RequestDenied {
        #       proxy_pass http://127.0.0.1:8080;
        #}

        error_page 404 /404.html;


}

但它似乎根本不起作用。但是,每当我尝试使用 www.subdomain.domain.com 访问该站点时,我都无法访问该站点,但是 https://subdomain.domain.com 工作正常。任何关于这方面的建议都将非常感谢。

【问题讨论】:

  • 你有很多语法错误。你重启nginx了吗?

标签: nginx


【解决方案1】:

你在 nginx 配置中有错字(server_name 而不是 server),并尝试用更正确的方式返回而不是重写:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-10
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多