目前我使用此功能将domain.com
重定向到https://www.domain.com
server {
#listen 80 is default
server_name domain.com;
return 301 https://www.domain.com$request_uri;
}
server {
listen 443 ;
server_name www.domain.com;
//rest of config goes here
}
然而,由于https://domain.com
未重定向到https://www.domain.com
如何修改以上内容以实现该目标......
答案 0 :(得分:4)
您没有设置服务器来捕获非www ssl,您可以通过使相同的重定向服务器同时捕获来解决这个问题
server {
listen 80;
listen 443; # add this line
server_name domain.com;
return 301 https://www.domain.com$request_uri;
}
server {
listen 443 ;
server_name www.domain.com;
//rest of config goes here
}
答案 1 :(得分:4)
我通过添加另一个服务器块来修复它以捕获非www ssl
向穆罕默德·阿布沙迪致敬,
server {
listen 80;
listen 443;
ssl on;
ssl_certificate /etc/ssl/domain_bundle.crt;
ssl_certificate_key /etc/ssl/domain.key.nopass;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
server_name domain.com;
return 301 https://www.domain.com$request_uri;
}
server {
listen 443 ;
server_name www.domain.com;
//rest of config goes here
}