“Nginx http重定向到https”的版本间的差异
跳到导航
跳到搜索
第44行: | 第44行: | ||
</pre> | </pre> | ||
+ | |||
+ | =rewrite方法= | ||
+ | <pre> | ||
+ | server { | ||
+ | listen 192.168.1.111:80; | ||
+ | server_name test.com; | ||
+ | |||
+ | rewrite ^(.*)$ https://$host$1 permanent; | ||
+ | } | ||
+ | </pre> | ||
+ | |||
=see also= | =see also= | ||
[https://blog.hcl.moe/archives/729 Nginx下HTTP强制重定向至HTTPS] | [https://blog.hcl.moe/archives/729 Nginx下HTTP强制重定向至HTTPS] |
2020年4月23日 (四) 08:12的版本
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; }