Nginx http重定向到https
301强制重定向
#注意 是加在 ssl cer 后面 ,加在 前面 可能当作 是 80的 不生效呢 #4 blog server { listen 80; # listen [::]:80 ipv6only=on default_server; listen 443 default ssl; #listen [::]:80; #ssl on; ssl_certificate /etc/letsencrypt/live/linuxchina.net/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/linuxchina.net/privkey.pem; server_name linuxchina.net www.linuxchina.net; #by evan if ($scheme = http) { return 301 https://$server_name$request_uri; } #by evan # server_name blog.linuxchina.net; charset utf-8; root /data/www/evan; index index.php index.html index.htm; #简约格式 server { listen 80; ... return 301 https://$server_name$request_uri; } server { listen 443; ... }
rewrite方法
server { listen 192.168.1.111:80; server_name test.com; rewrite ^(.*)$ https://$host$1 permanent; }