【问题标题】:Nginx redirect https->http(reverse proxy)->port(docker container)Nginx 重定向 https->http(反向代理)->port(docker 容器)
【发布时间】: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


【解决方案1】:

使用letsencrypt获取免费证书,然后使用https或重定向到http是我的解决方案。

感谢@RichardSmith

【讨论】:

    【解决方案2】:

    您可以尝试通过 ngx_stream_core_module 使用 TCP 重新流式传输 http://nginx.org/en/docs/stream/ngx_stream_core_module.html

    stream {
        server {
            listen 443;
            proxy_pass 127.0.0.1:80;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-04
      • 1970-01-01
      • 2018-03-20
      • 2022-01-20
      • 2019-03-11
      • 2016-09-30
      • 2021-04-06
      • 2015-01-04
      相关资源
      最近更新 更多