【问题标题】:How to make docker application use port 80 (http) instead of 443 (https)如何使 docker 应用程序使用端口 80 (http) 而不是 443 (https)
【发布时间】:2017-10-29 03:46:00
【问题描述】:

我最近在运行 Apache(禁用 SSL)的 Ubuntu 服务器上安装了 this web application

不管我尝试了多少,我都无法让应用程序使用 http。尝试了-p 标志。然后它会暴露端口 443 并绑定其他东西。我讨厌关于 SSL 的浏览器警告。我只想在端口 8080 上使用 http。

应用程序使用只监听 443 的 nginx。我希望我的应用程序 URL 看起来像 http://localhost:8080 这个应用程序使用 Google OAuth 进行登录。我假设它可以在 http 上运行。

如何让它在 http 中工作?

【问题讨论】:

    标签: apache http ssl nginx docker


    【解决方案1】:

    您必须编辑 nginx.conf 才能使用纯 http(nginx 永远不会在 https 端口上使用 http,仅用于一些错误)

    变化:

    listen 443;
        server_name localhost;
    
        access_log /dev/stdout;
        error_log /dev/stderr;
    
        ssl on;
        ssl_certificate /src/openseedbox/conf/host.cert;
        ssl_certificate_key  /src/openseedbox/conf/host.key;
    

    收件人:

    listen 8080;
        server_name localhost;
    
        access_log /dev/stdout;
        error_log /dev/stderr;
    

    然后在 docker build 之后运行:

    docker run -p 8080:8080 .......
    

    或者,您可以将 Apache 设置为 HTTP 虚拟主机,反向代理到安全的 HTTPS nginx。但是我觉得修改nginx配置比较容易。


    方法 #2

    你可以添加另一个nginx容器来充当反向代理,不确定后面的应用程序是否会崩溃,但它充当http“plainer”:

    docker-compose.yml

    # Add this:
    plain_nginx:
        image: nginx
        volumes:
          - ./plain_nginx.conf:/etc/nginx/conf.d/default.conf
        ports:
          - 8080:80
        links:
          - openseedbox
    

    plain_nginx.conf

    server {
        listen 80;
        server_name _;
    
        access_log /dev/stdout;
        error_log /dev/stderr;
    
        location / {
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Ssl on;
          proxy_pass https://openseedbox;
        }
    }
    

    然后从该仓库中的./docker/ 目录执行:

    docker-compose up
    

    那么你有 http://localhost:8080 作为 SSL 东西的反向代理

    【讨论】:

    • 试过这个。但应用程序仍然使用端口 443
    • 我添加了方法 #2。让我知道它是否适合您
    • 不会有这样的plain http to https port,因为新的 nginx 反向代理到 https 端口使用 SSL 后面,你可以在这里看到proxy_pass https://openseedbox;。如果 openseedbox 应用程序本身重新检查并抱怨,仍然可能存在一些问题。但是请尝试一下,我不能,因为我没有提供 Google ID 和那些东西
    • 是的,确实如此。但这是我发布的第一种方法。使用第二个,您只需在 docker-compose.yml 中添加一个文件和一个服务
    • 没问题!
    猜你喜欢
    • 2014-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-02
    • 2021-04-09
    • 1970-01-01
    • 2021-09-17
    • 2020-04-23
    相关资源
    最近更新 更多