如何在nginx上强制http://example.com
到https://example.com
?
这是我当前的配置,仅当键入example.com
并按指定重定向到https时,它才起作用,但是如果我使用显式方案http http://example.com
键入,则不重定向到https。
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name _;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/nginx/ssl/example.com.crt;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
...
}