【问题标题】:Docker port is not working over https after setting up an SSL over ubuntu nginx在 ubuntu nginx 上设置 SSL 后,Docker 端口无法通过 https 工作
【发布时间】:2019-04-01 03:59:19
【问题描述】:

我将 Letsencrypt 证书直接设置到运行 Nginx 的 AWS EC2 Ubuntu 实例和使用端口 9998 的 docker 服务器。域设置在 Route 53 上。Http 被重定向到 https。

所以https://example.com 工作正常,但https://example.com:9998 得到 ERR_SSL_PROTOCOL_ERROR。如果我使用像http://10.10.10.10:9997 这样的IP 地址正在工作并检查使用端口9998 的服务器没问题。

docker上服务器的快照是:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
999111000        img-server         "/bin/sh -c 'java -j…"   21 hours ago        Up 21 hours         0.0.0.0:9998->9998/tcp   hellowworld

Nginx 和使用端口 9998 的服务器之间似乎缺少某些东西。我该如何修复它?

【问题讨论】:

    标签: docker nginx amazon-ec2 lets-encrypt


    【解决方案1】:

    您在哪里配置了 ssl 证书?只有 Nginx?

    使用ssl协议无法访问https://example.com:9998的原因是该端口提供的是http服务而不是https。

    我建议不要发布helloworld的9998,用nginx代理所有流量(如果Nginx也是用docker启动的,在同一个网络)。

    在Nginx中配置https,源站提供http。

    这是一个示例配置https://github.com/newnius/scripts/blob/master/nginx/config/conf.d/https.conf

    server {
        listen      80;
        server_name example.com;
        return      301 https://example.com$request_uri;
    }
    server {
        listen      443;
        server_name example.com;
    
        access_log  logs/example.com/access.log  main;
        error_log   /var/log/nginx/debug.log debug;
    
        ssl on;
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    
        location / {
            proxy_pass       http://apache:80;
            proxy_set_header Host $host;
            proxy_set_header CLIENT-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    
        location ~ /.well-known {
            allow all;
            proxy_pass  http://apache:80;
        }
    
        # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store(Mac).
        location ~ /\. {
            deny all;
        }
    }
    

    【讨论】:

    • SSL 在 Nginx 上而不是在 Docker 内。对apache:80 感到困惑。首先,是端口 80 还是 9998。因为服务在端口 9998 上运行,所以它必须在某个地方告诉 Nginx - 困惑。其次,是 apache:80 还是 9998 还是 nginx:80?据我所知,Nginx 正在运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-30
    • 2020-09-23
    • 2021-06-01
    • 1970-01-01
    • 2021-02-28
    • 1970-01-01
    相关资源
    最近更新 更多