2014-02-21 38 views
2

我一直在寻找从www.domain.com重定向我的网站domain.com的nginx的网址从万维网重定向到没有WWW为HTTPS

我跟着这个Nginx no-www to www and www to no-www

但是对于普通http://www.domain.com它重定向到domain.com的

但是当我尝试https://www.domain.com它保持原样,不重定向到https://domain.com

我不知道我错过了什么

server { 
    listen 80; 
    server_name www.domain.com; 
    // $scheme will get the http protocol 
    // and 301 is best practice for tablet, phone, desktop and seo 
    return 301 $scheme://domain.com$request_uri; 
} 

server { 
    listen 80; 
    server_name domain.com; 
    // here goes the rest of your config file 
    // example 
    location/{ 

     rewrite ^/cp/login?$ /cp/login.php last; 
     // etc etc... 

    } 
} 
+0

请考虑发布您的nginx配置。 – bredikhin

+0

我遵循http://stackoverflow.com/questions/7947030/nginx-no-www-to-www-and-www-to-no-www的第一个答案,我编辑了我的问题哪一个我从链接 –

+0

,因此,那么你可能在错误的端口上收听https,下面的答案是非常简单的。 – bredikhin

回答

4

您需要设置另一台服务器侦听到HTTPS,并将其重定向

server { 
    listen 443 ssl; 
    server_name www.example.com; 
    # add ssl config to avoid certificate warning 
    return 301 https://example.com; 
} 

你可以在一台服务器总结HTTP和HTTPS重定向

server { 
    listen 80 443; 
    server_name www.example.com; 
    ssl on; 
    # ssl config 
    return 301 $scheme://example.com; 
} 
相关问题