可以把所有的HTTP请求通过rewrite重写到HTTPS上
配置
方法一
1 server{ 2 listen 80; 3 server_name XXXXX.com; //你的域名 4 rewrite ^(.*)$ https://XXXXXX.com permanent; 5 location ~ / { 6 index index.html index.php index.htm; 7 } 8 }
方法二
1 server{ 2 listen 80; 3 server_name XXXXX.com; //你的域名 4 return 301 https://$server_name$request_uri; 5 location ~ / { 6 index index.html index.php index.htm; 7 } 8 }
方法三
1 server{ 2 listen 80; 3 server_name XXXXX.com; //你的域名 4 rewrite ^(.*)$ https://$host$1 permanent; 5 location ~ / { 6 index index.html index.php index.htm; 7 } 8 }
497 – normal request was sent to HTTPS
当前站点只允许HTTPS访问,当使用HTTP访问nginx会报出497错误码
可以使用error_page 把497状态码链接重新定向到HTTPS域名上
1 server{ 2 listen 80; 3 server_name XXXXX.com; //你的域名 4 error_page 497 https://$host$uri?$args; 5 location ~ / { 6 index index.html index.php index.htm; 7 } 8 }
<html>
<meta http-equiv=”refresh” content=”0;url=https://XXXX.com/”>
</html>
1 server{ 2 listen 80; 3 server_name XXXXX.com; //你的域名 4 location ~ / { 5 root /var/www/test/; 6 index index.html index.php index.htm; 7 } 8 error_page 404 https://xxxx.com 9 }
原文:https://www.cnblogs.com/lpjnote/p/10759847.html