-
nginx 强制https
通常有如下两种方法强制https
推荐第二种,第二种更高效
1、使用nginx的rewrite方法server { listen 80; server_name xxx.com; rewrite ^(.*)$ https://$host$1 permanent; }
2、使用nginx的301状态码
server { listen 80; listen 443; server_name xxx.com; ssl on; ssl_certificate /data/www-key/xxx.pem; ssl_certificate_key /data/www-key/xxx.key; if ($scheme = http) { return 301 https://$server_name$request_uri; } }