nginx将所有http重定向到https to www附加,例如:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.example.com;
...
}
当访问" https://example.com"时,我会收到一个ssl_common_name错误,参考default_server。请注意,如果没有www,它是如何https的。我需要在https上强制www,在这种情况下我想重写吗?
访问时如何有效地返回/重写URL?我需要没有www的https才能使用www。
返回https。以下是正确的吗?如果是这样,我应该从第一个服务器块中删除" SSL HTTP2"?
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.example.com;
...
}
我感谢您的时间。
您可以从第二个块中删除HTTP2,但您需要保留SSL。
休息一切看起来都不错