如何在端口443和端口80的docker群中创build一个nginx服务

我正在尝试在生产环境中的2个节点的Docker群中创build带有2个副本的nginx服务。 节点是在数字海洋中创build的。 这个nginx服务是作为apache虚拟主机的反向代理(https < – > http)。 要创build我使用的nginx服务:

docker service create –replicas 2 -p 80:80 –p 443:443 –name webserver –mount type = bind,source = / environments / ssl-env,destination = / etc / nginx / ssl –mount type = bind,source = / conf / nginx.conf,destination = / etc / nginx / nginx.conf –mount type = bind,source = / middleware,destination = / etc / nginx / conf.d nginx

我运行这个命令后,服务无法启动,没有任何有用的错误消息。 但是,只有在worker节点中,docker守护程序才会监听端口443:

netstat -tulpn | grep :443 tcp6 0 0 :::443 :::* LISTEN 5797/dockerd 

另外,当我在nginx.conf中注释443的https部分时,我的nginx服务被创build并运行成功,但是我想要使用https部分。 你有什么主意吗? Docker版本17.05.0-ce,build 89658be。 这里是nginx.conf的一部分:

 #http server { listen 80 ; server_name api.hotelgenius.net; # redirect http to https ## rewrite ^ https://$server_name$request_uri permanent; } #https #server { listen 443 ; server_name api.hotelgenius.net; error_log /var/log/nginx/api_error.log; access_log /var/log/nginx/api_access.log; ssl on; ssl_certificate /etc/nginx/ssl/api.hotelgenius.crt; ssl_certificate_key /etc/nginx/ssl/api.hotelgenius.key; ssl_client_certificate /etc/nginx/ssl/api.hotelgenius.cer; location / { proxy_pass http://hotelgenius/; proxy_set_header Host $host; proxy_redirect http:// https://; } 

在将nginx.conf中的容器名称replace为docker堆栈中相应的服务名称后,Nginx服务已成功部署。 例如在修复之前,我已经在nginx.conf

 location / { proxy_pass http://hotelgenius/; proxy_set_header Host $host; proxy_redirect http:// https://; } 

其中“hotelgenius”是一个容器的名称。我必须用服务名称replace“hotelgenius”,因为在docker-compose.yml中不再支持版本3的容器名称。