1

I'm trying to setup a docker swarm with multiple networks, so I can run a set of services (in different versions) on different networks on the swarm. I also want to access these services outside of the swarm, but do not want to fight for ports each time I startup a new service

To handle this I'm trying to setup a proxy using nginx, so I can point http://service-v1.swarm-master/config/ to my etcd-viewer running at http://etcd-viewer.rest-test:8080 on the rest-test overlay network; all on the swarm. This is giving me some headache as of now!

When going to http:// service-v1.swarm-master/config/ I'm met with a 404 page:

HTTP ERROR 404
Problem accessing /config/. Reason:
Not Found
Powered by Jetty://

From inside my nginx container I have made sure that I can in fact reach the services that I'm trying to access by doing a ping -c1 etcd-viewer and ping -c1 etcd-viewer.rest-test. There's access to both from inside the running nginx container.

So why does my nginx.conf not seem to work? It is mounted at /etc/nginx/conf.d/.

resolver 127.0.0.11;

upstream config {
  server etcd-viewer.rest-test:8080;
}

log_format compression '$remote_addr - $remote_user [$time_local] '
                           '"$request" $status $request_body ($body_bytes_sent) '
                           '"$http_referer" "$http_user_agent" "$gzip_ratio"';

server {
  listen 80;
  #server_name docker.cdrator.com;

  access_log /var/log/nginx/access.log compression;

  # disable any limits to avoid HTTP 413 for large image uploads
  client_max_body_size 0;

  # required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486)
  chunked_transfer_encoding on;

  location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

  location /config/ {
    proxy_pass                          http://config;
    proxy_set_header  Host              $http_host;   # required for docker client's sake
    proxy_set_header  X-Real-IP         $remote_addr; # pass on real client's IP
    proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto $scheme;
    proxy_read_timeout                  900;
  }

  location /basic_status {
      stub_status;
  }
}
030
  • 5,901
  • 13
  • 68
  • 110
  • The below location config did the trick. Problem solved! `location /etcd { proxy_set_header Host $http_host; # required for docker client's sake proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 900; proxy_pass http://config; }` – Tue Dissing Nov 23 '16 at 12:30
  • Why are you debugging nginx for this error? The 404 you received back appears to be from the proxied target running Jetty, not nginx. – BMitch Nov 23 '16 at 13:26

1 Answers1

0

Did a small change to the config and decided to override the main nginx.conf. This is not that clean, but works for now.

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;


    upstream config {
      server etcd-viewer.rest-test:8080;
    }

    server {
      listen 80;

      location /etcd {
        proxy_set_header  Host              $http_host;   # required for docker client's sake
        proxy_set_header  X-Real-IP         $remote_addr; # pass on real client's IP
        proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header  X-Forwarded-Proto $scheme;
        proxy_read_timeout                  900;

        proxy_pass                          http://config;
      }

      location /basic_status {
          stub_status;
      }
    }

    include /etc/nginx/conf.d/*.conf;


}