nginx 访问http80自动跳转https443端口

在nginx配置文件server 段里面中加入下面代码:

server {

if ($server_port = 80){
return 301 https://$server_name$request_uri;}

if ($scheme = http){
return 301 https://$server_name$request_uri;}

error_page 497 https://$server_name$request_uri;

}

 

分享