【发布时间】:2021-05-01 13:33:48
【问题描述】:
所以我有两个域:
example.com
example.ca
这是一个运行 nginx 的 docker 容器,我正在尝试完成 http 到 https 的重定向和 www 到非 www 的重定向。
主机上的 Docker 绑定到端口 80 和 443。要明确的是,进出服务器的流量正常工作。
问题是 www 重定向似乎被忽略了。
当用户转到http://www.example.com 时,我希望他们被重定向到https://example.com
实际情况是它们被重定向到https://www.example.com
所以 https 重定向 100% 的时间都有效,但由于某种原因,nginx 无法在没有 www 的情况下执行重定向
值得注意的是,我们正在使用 CloudFlare 来替换我们的自签名证书。那么也许是 CloudFlare 导致了这个问题?
这是我的重定向。
server {
listen 8080;
listen 8443;
server_name www.example.com;
return 301 https://$host$request_uri?$args;
}
server {
listen 8080;
listen 8443;
server_name www.example.ca;
return 301 https://$host$request_uri?$args;
}
# Force http to https
server {
listen 8080;
server_name example.com;
return 301 https://$host$request_uri?$args;
}
server {
listen 8080;
server_name example.ca;
return 301 https://$host$request_uri?$args;
}
【问题讨论】:
标签: docker nginx docker-compose nginx-config