我想運行一個docker-compose與Nginx,它將只是其他docker-compose服務的代理。https代理到本地主機後nginx超時
這裏是我的搬運工,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"
所以它會虎視眈眈於./config/nginx/conf.d
目錄中指定的服務端口80或443,並代理他們所有的連接。
下面是示例服務./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.com
,https://domain_name.com
和http://www.domain_name.com
到https://www.domain_name.com
並代理特定本地主機服務。
這裏是我的具體服務搬運工,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:8888
或https://www.domain_name.com:4433
你會得到的內容。當您從運行docker的服務器上甩到localhost:8888
或https://localhost:4433
時,您也會收到內容。
現在我的問題。
當我去瀏覽器和輸入domain_name.com
,www.domain_name.com
或https://www.domain_name.com
什麼也沒有發生。即使當我從本地機器捲曲到這個域時,我也超時了。
我有搜索一些信息「nginx代理https到localhost」,但注意到我的作品。