2014-02-21 41 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; 
} 
相關問題