【问题标题】:nginx timeout after https proxy to localhosthttps代理到本地主机后的nginx超时
【发布时间】:2017-04-24 21:02:06
【问题描述】:

我想用 Nginx 运行一个 docker-compose,它只是其他 docker-compose 服务的代理。

这是我的带有代理的 docker-compose.yml:

version: '2'

services:
    storage:
        image: nginx:1.11.13
        entrypoint: /bin/true
        volumes:
            - ./config/nginx/conf.d:/etc/nginx/conf.d
            - /path_to_ssl_cert:/path_to_ssl_cert
    proxy:
        image: nginx:1.11.13
        ports:
            - "80:80"
            - "443:443"
        volumes_from:
            - storage
        network_mode: "host"

因此它会抓取到端口 80 或 443 的所有连接,并将它们代理到./config/nginx/conf.d 目录中指定的服务。

这里是示例服务./config/nginx/conf.d/domain_name.conf:

server {
    listen 80;
    listen 443 ssl;
    server_name domain_name.com;

    ssl_certificate     /path_to_ssl_cert/cert;
    ssl_certificate_key /path_to_ssl_cert/privkey;

    return 301 https://www.domain_name.com$request_uri;
}

server {
    listen 80;
    server_name www.domain_name.com;

    return 301 https://www.domain_name.com$request_uri;

#    If you uncomment this section and comment return line it's works
#    location ~ {
#        proxy_pass http://localhost:8888;
#        # or proxy to https, doesn't matter 
#        #proxy_pass https://localhost:4433;
#    }
}

server {
    listen 443 ssl;
    server_name www.domain_name.com;

    ssl on;
    ssl_certificate     /path_to_ssl_cert/cert;
    ssl_certificate_key /path_to_ssl_cert/privkey;

    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-Client-Verify SUCCESS;
        proxy_set_header X-Client-DN     $ssl_client_s_dn;
        proxy_set_header X-SSL-Subject   $ssl_client_s_dn;
        proxy_set_header X-SSL-Issuer    $ssl_client_i_dn;

        proxy_pass https://localhost:4433;
#       like before
#       proxy_pass http://localhost:8888;
    }
}

它将所有请求http://domain_name.comhttps://domain_name.comhttp://www.domain_name.com重定向到https://www.domain_name.com并将其代理到特定的本地主机服务。

这是我的具体服务 docker-compose.yml

version: '2'

services:
    storage:
        image: nginx:1.11.13
        entrypoint: /bin/true
        volumes:
            - /path_to_ssl_cert:/path_to_ssl_cert
            - ./config/nginx/conf.d:/etc/nginx/conf.d
            - ./config/php:/usr/local/etc/php
            - ./config/php-fpm.d:/usr/local/etc/php-fpm.d
            - php-socket:/var/share/php-socket
    www:
        build:
            context: .
            dockerfile: ./Dockerfile_www
        image: domain_name_www
        ports:
            - "8888:80"
            - "4433:443"
        volumes_from:
            - storage
        links:
            - php
    php:
        build:
            context: .
            dockerfile: ./Dockerfile_php
        image: domain_name_php
        volumes_from:
            - storage

volumes:
    php-socket:

因此,当您转到http://www.domain_name.com:8888https://www.domain_name.com:4433 时,您将获得内容。当你从运行 docker 的服务器 curl 到 localhost:8888https://localhost:4433 时,你也会得到内容。

现在是我的问题。

当我进入浏览器并输入 domain_name.comwww.domain_name.comhttps://www.domain_name.com 时,什么也没有发生。即使我从本地机器卷曲到这个域,我也会超时。

我搜索了一些信息“nginx 代理 https 到 localhost”,但注意到对我有用。

【问题讨论】:

    标签: nginx docker proxy


    【解决方案1】:

    我有办法!

    当我在 docker-compose.yml 中为我的代理设置 network_mode: "host" 时,我认为 ports: 条目仍然有效,但没有。

    现在代理在我的主机网络中工作,因此它使用本地端口并省略 docker-compose.yml 中的 ports: 条目。这意味着我已经在我的服务器上手动打开了 80 和 443 端口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-21
      • 1970-01-01
      • 2017-07-15
      • 2013-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多