[英]Nginx - redirect correctly from http:// to https:// without www
Following my configuration file: 按照我的配置文件:
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
}
I don't understand why http://www.example.com
redirects to https://www.example.com
and then to https://example.com
. 我不明白为什么
http://www.example.com
重定向到https://www.example.com
,然后再重定向到https://example.com
。 How to redirect from http://www.example.com
directly to https://example.com
? 如何从
http://www.example.com
直接重定向到https://example.com
?
NGINX config for redirect from HTTP to HTTPS without WWW: NGINX配置,用于在没有WWW的情况下从HTTP重定向到HTTPS:
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;
}
启用HSTS后,第一次重定向将直接由您的浏览器完成,而无需任何网络交互。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.