方法一 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; 方法二 if ($server_port !~ 443){ rewrite ^(/.*)$ https://$host$1 permanent; } 方法三 if ($host = "xxx.selinux.cn") { rewrite ^/(.*)$ https://xxx.selinux.cn permanent; }