今天有位客户问ytkah在nginx服务器如何设置http 301重定向到https,其实不难。他的服务器安装宝塔面板了,更好操作了。进入站点设置的配置文件,如下图所示,在第11行左右加入跳转代码
#301-START
if ($host ~ '^abc.com'){
return 301 https://www.abc.com/$request_uri;
}
#301-END
#301-START
if ( $scheme = http ){
return 301 https://$server_name$request_uri;
#或return 301 https://www.abc.com/$request_uri;
}
#301-END
另外一种方法是直接在nginx配置文件里改,一般是在会在 /usr/local/nginx/conf/nginx.conf
server {
listen 80;
...
return 301 https://$server_name$request_uri;
}
server {
listen 443;
...
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有