配置我的Web服务器后,通过IP或域名访问时,https重定向如下:
http://192.168.10.5 to https://192.168.10.5
http://www.example.com to https://www.example.com
然而,我想要http://192.168.10.5和http://www.example.com重定向至https://www.example.com。
基本 Nginx 配置:
server {
listen 80 default_server;
server_name 192.168.10.5 www.example.com;
location / {
rewrite ^(.*) https://$http_host$1 permanent;
}
}
server {
listen 443 http2 ssl;
server_name www.example.com;
root /var/www/example/html;
ssl_certificate /etc/ssl/certs/mycert.crt;
ssl_certificate_key /etc/ssl/private/mykey.key;
}
答案1
server {
listen 80 default_server;
server_name 192.168.10.5 www.example.com;
location / {
rewrite ^(.*) https://www.example.com$1 permanent;
}
}
server {
listen 443 http2 ssl;
server_name 192.168.10.5;
ssl_certificate /etc/ssl/certs/mycert.crt;
ssl_certificate_key /etc/ssl/private/mykey.key;
location / {
rewrite ^(.*) https://www.example.com$1 permanent;
}
}
server {
listen 443 http2 ssl;
server_name www.example.com;
root /var/www/example/html;
ssl_certificate /etc/ssl/certs/mycert.crt;
ssl_certificate_key /etc/ssl/private/mykey.key;
}