lnmp1.4使用https,301跳转有个小疑问
lnmp1.4使用https,301跳转有个小疑问假设域名为abc.comabc.com跳转到www.abc.com这样做没问题:
server
{
listen 80;
#listen [::]:80;
server_name www.abc.com;
……
}
server
{
listen 80;
#listen [::]:80;
server_name abc.com;
return 301 http://www.abc.com$request_uri;
}
现在的情况是我需要把abc.com、www.abc.com、https://abc.com这三种情况都跳转到https://www.abc.com,于是我这样写
server
{
listen 80;
#listen [::]:80;
server_name abc.com;
return 301 https://www.abc.com$request_uri;
}
server
{
listen 80;
#listen [::]:80;
server_name www.abc.com;
return 301 https://www.abc.com$request_uri;
}
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name www.abc.com;
index index.html index.htm index.php default.html default.htm default.php;
……
}
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name abc.com;
return 301 https://www.abc.com$request_uri;
}
发现最后这个https://abc.com跳转到https://www.abc.com实现不了,似乎是443端口的server_name abc.com;并不是https://abc.com,跳转失败,虽然一般是直接输入域名,很少有人会输入https://abc.com来访问,但还是有点担心。
我装的wordpress,本来就可以自动跳,去掉最后这个后访问https://abc.com会跳转到https://www.abc.com,但可能是跳转了两步,感觉效率比nginx直接跳转慢一些。所以请大神指点,如何配置能直接跳转?谢谢! 两个http的写成一块就行了
ssl的那个301是有问题的既然是ssl站点即使只是做301,也应该按正常ssl站点设置上ssl证书、key等那些配置参数
回复 2# 的帖子
server{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name abc.com;
#index index.html index.htm index.php default.html default.htm default.php;
#root/home/wwwroot/www.abc.com;
ssl on;
ssl_certificate /etc/letsencrypt/live/www.abc.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.abc.com/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
# openssl dhparam -out /usr/local/nginx/ssl/dhparam.pem 2048
ssl_dhparam /usr/local/nginx/ssl/dhparam.pem;
return 301 https://www.abc.com$request_uri;
}
不知道起作用没,因为wp本来就会跳转,似乎是可以
[ 本帖最后由 wxfly 于 2017-3-2 08:31 编辑 ]
页:
[1]