【发布时间】:2019-02-13 08:52:25
【问题描述】:
上下文
简单设置
- 将 8090 公开为网站(节点、快递)的 docker 容器
- 一个 nginx conf 暴露 80 并将其映射到 localhost 8090
问题
我没有付费 SSL 证书,我希望将尝试访问 https 的最终用户重定向到 http。
我尝试过重定向、重写,并在下面简单地听一下.. 没有成功。浏览器会返回“ERR_SSL_PROTOCOL_ERROR”。
server {
listen 80;
listen 443;
ssl off;
server_name xxxx.com;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass "http://0.0.0.0:8090";
}
}
问题
您能否建议最干净的重定向 https->http(reverse proxy) 的方法?问候
编辑 1
以下配置导致浏览器“ERR_SSL_PROTOCOL_ERROR”。
server {
listen 80;
server_name xxxx.com;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass "http://0.0.0.0:8090";
}
}
server {
listen 443;
server_name xxxx.com;
rewrite ^(.*) http://$host$1 permanent;
}
【问题讨论】:
-
@wpercy 感谢您的研究,我之前审查并尝试过该解决方案,但无法使其工作,请参阅编辑 1。
-
如果您在不启用 SSL 的情况下尝试将
https重定向到http,您不能,这是不可能的。要使用https(甚至重定向它),您需要一个证书。 -
@RichardSmith 有没有办法平滑地重定向最终用户?例如 [最终用户浏览器 https://example.org] -> [他被重定向到 http://example.org 并且浏览器在地址栏附近显示不安全标志] ?如果我启用 SSL(重定向)并放置自签名证书,问题是最终用户将看到完整的“此站点不安全”chrome 错误页面。
-
用户键入
https的那一刻,预计连接将是安全的,并且您的站点将向浏览器提供有效的证书。不让加密解决这个问题吗? -
通过让加密解决的问题。谢谢@RichardSmith。
标签: docker nginx nginx-reverse-proxy