配置好我的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 个回答