我试图用nginx将类似https://example.com的https域重定向到https://example.com/something。当我在浏览器中使用http://example.com但不使用https://example.com时,它可以正常工作。我的配置如下。
server {
listen 80;
server_name example.com;
return 301 https://$server_name/something;
}
server {
listen 443;
server_name example.com;
return 301 https://$server_name/something;
}谢谢!
发布于 2022-02-25 18:02:19
ssl_certificate和ssl_certificate_key指令。您必须在HTTP/2的侦听指令上指定<>ssl和HTTP 2。
对于HTTP/3 HTTP 3意味着强制ssl,因此在这种情况下不应该指定<>ssl指令。
你应该这样做:
server {
listen 0.0.0.0:80 default_server;
listen [::]:80 default_server;
location / {
return 308 https://$host$request_uri/something;
}
}
server {
listen 0.0.0.0:443 http3 reuseport;
listen 0.0.0.0:443 http2 ssl;
listen [::]:443 http3 reuseport;
listen [::]:443 http2 ssl;
server_name $YOURDOMAIN;
ssl_certificate $CERT_PATH;
ssl_certificate_key $CERT_KEY;
[...]
}还请参阅Mozilla配置工具以帮助您:https://ssl-config.mozilla.org/
并根据你的需要进行调整。
注意:上面关于http3的配置行是有用的,如果您使用HTTP/3支持编译NGINX,它只在nginx-quic分支上可用。
https://serverfault.com/questions/1094522
复制相似问题