繁体   English   中英

https代理到localhost后的nginx超时

[英]nginx timeout after https proxy to localhost

我想用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并将其代理到特定的localhost服务。

这是我的特定服务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您将获得内容。 当您从运行https://localhost:4433的服务器卷曲到localhost:8888https://localhost:4433 ,您也将获得内容。

现在我的问题。

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

我搜索了一些信息“nginx代理https到localhost”,但注意到我的工作。

我有解决方案!

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM