nginx没有使用重写剥离www

时间:2015-04-21 04:09:59

标签: nginx

我想在我的nginx配置中从我的网址中删除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工作正常。对此有任何建议都非常感谢。

1 个答案:

答案 0 :(得分:0)

你在nginx配置中输入错误(server_name而不是服务器),并尝试以更正确的方式重写而不是重写:

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