I have a service running across 4 swarm nodes (ServiceA) and a Nginx service running across 4 nodes on the same Swarm. The Nginx service exposes/publishes ports 80 and 443. All the services are connected to the same user-defined overlay network and most importantly I can curl/ping the service name (ServiceA) from within the containers so all is working so far.
My question is how do I get Nginx upstream to work with the service names? I've read a lot and tried adding this to the nginx.conf resolver 127.0.0.11 ipv6=off;
but it has not helped and the Nginx service will not start. Any ideas on how to get Nginx see the Docker network DNS names?
This is my nginx.conf
events {
worker_connections 4096;
}
http {
include /etc/nginx/conf/*.conf;
include /etc/nginx/mime.types;
proxy_intercept_errors off;
proxy_send_timeout 120;
proxy_read_timeout 300;
upstream serviceA {
ip_hash;
server serviceA:8081;
}
server {
listen 80 default_server;
resolver 127.0.0.11 ipv6=off;
keepalive_timeout 5 5;
proxy_buffering off;
underscores_in_headers on;
location ~ ^/serviceA(?<section>.*) {
access_log /var/log/nginx/access.log nginx_proxy_upstream;
proxy_pass http://serviceA/$section$is_args$query_string;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 443 ssl;
resolver 127.0.0.11 ipv6=off;
keepalive_timeout 5 5;
proxy_buffering off;
underscores_in_headers on;
# allow large uploads
client_max_body_size 10G;
ssl_certificate /etc/nginx/ssl/myKey.crt;
ssl_certificate_key /etc/nginx/ssl/myKey.key;
location ~ ^/serviceA(?<section>.*) {
access_log /var/log/nginx/access.log nginx_proxy_upstream;
proxy_pass http://serviceA/$section$is_args$query_string;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}