[英]How to create an nginx service in a docker swarm at port 443 and 80
我正在尝试在生产环境中的2个节点的docker群中创建2个副本的nginx服务。 节点是在数字海洋中创建的。 此nginx服务将充当apache虚拟主机的反向代理(https <–> http)。 要创建nginx服务,请使用:
docker服务create --replicas 2 -p 80:80 --p 443:443 --name webserver --mount type = bind,source = / environments / ssl-env,destination = / etc / nginx / ssl --mount类型= bind,source = / conf / nginx.conf,目的地= / etc / nginx / nginx.conf-挂载类型= bind,source = /中间件,目的地= / etc / nginx / conf.d nginx
运行此命令后,服务无法启动,没有任何有用的错误消息。 但是,仅在工作程序节点中,docker守护程序会侦听端口443:
netstat -tulpn | grep :443
tcp6 0 0 :::443 :::* LISTEN 5797/dockerd
另外,当我在nginx.conf中对监听443的https部分进行注释时,我的nginx服务已创建并成功运行,但是我当然想使用https部分。 你有什么主意吗? Docker版本17.05.0-ce,内部版本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中的容器名称替换为docker堆栈中的相应服务名称后,Nginx服务已成功部署。 例如,在修复之前,我在nginx.conf中
location / {
proxy_pass http://hotelgenius/;
proxy_set_header Host $host;
proxy_redirect http:// https://;
}
其中'hotelgenius'是容器的名称。我不得不用服务名称替换'hotelgenius',因为在docker-compose.yml版本中不再支持3容器名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.