gpt4 book ai didi

redirect - Nginx - 从 http ://to https://without www 正确重定向

转载 作者:太空宇宙 更新时间:2023-11-03 13:25:11 27 4
gpt4 key购买 nike

按照我的配置文件:

server {
listen [::]:443 ipv6only=off ssl;
server_name www.example.com;
// ssl stuff
return 301 https://example.com$request_uri;
}

server {
listen [::]:80 ipv6only=off;
return 301 https://example.com$request_uri;
}

server {
listen [::]:443 ssl;
server_name example.com;
// php and ssl stuff
}

我不明白为什么 http://www.example.com 重定向到 https://www.example.com 然后到 https//example.com。如何从 http://www.example.com 直接重定向到 https://example.com

最佳答案

在没有 WWW 的情况下从 HTTP 重定向到 HTTPS 的 NGINX 配置:

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 default_server;
listen [::]:443 ssl http2 default_server;
server_name example.com www.example.com;
##here-ssl-settings##
return 301 https://example.com$request_uri;
}

关于redirect - Nginx - 从 http ://to https://without www 正确重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34925537/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com