nginx http301强制跳转https、域名跳转到带www

http强制跳转到https
在nginx配置文件添加:
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}

Nginx跳转自动到带www域名规则配置:
在nginx大server中添加
server{
listen 80;
listen 443;
server_name www.xx.com xx.com;
if ($host != 'www.xx.com') {
rewrite ^/(.*)$https://www.xx.com/$1 permanent;
}

参考文档:http://wenku.it168.com/d_000938140.shtml

转载于:https://blog.51cto.com/lmy666/2322235

你可能感兴趣的:(nginx http301强制跳转https、域名跳转到带www)