3

I'm getting an error when using the docker image for setting up an nginx proxy server: nginx-proxy. If I hit and point on my site the response is incredibly slow to come back in some instances. This happens pretty much immediately, if I hit an endpoint three times, for example, in relatively quick succession. The log for nginx shows the following error:

2017/05/14 09:24:26 [warn] 26#26: *29 upstream server temporarily disabled while connecting to upstream, client: 10.255.0.2, server: [ip removed], request: "GET /documents/5918206a-8da0-4deb-86b2-6b627867e0d5 HTTP/1.1", upstream: "http://10.255.0.4:8080/documents/5918206a-8da0-4deb-86b2-6b627867e0d5", host: "[ip removed]"

The log for my back end service doesn't show any errors, so I'm not sure what may be going on. I am guessing it is a configuration issue with nginx, which could be fixed by changing the settings, but I am not sure where to start. Does anyone have any ideas?

My configuration looks like this in the end when the docker instance runs:

nginx.conf:

# cat nginx.conf

user  nginx;
worker_processes  1;

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


events {
    worker_connections  1024;
}


http {
    server_names_hash_bucket_size 128;
    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;

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

conf.d/default.conf:

daemon off;
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
  default $http_x_forwarded_proto;
  ''      $scheme;
}
# If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
# server port the client connected to
map $http_x_forwarded_port $proxy_x_forwarded_port {
  default $http_x_forwarded_port;
  ''      $server_port;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
  default upgrade;
  '' close;
}
# Set appropriate X-Forwarded-Ssl header
map $scheme $proxy_x_forwarded_ssl {
  default off;
  https on;
}
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
                 '"$request" $status $body_bytes_sent '
                 '"$http_referer" "$http_user_agent"';
access_log off;
# HTTP 1.1 support
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
# Mitigate httpoxy attack (see README for details)
proxy_set_header Proxy "";
server {
    server_name _; # This is just an invalid value which will never trigger on a real hostname.
    listen 80;
    access_log /var/log/nginx/access.log vhost;
    return 503;
}

upstream [ip removed] {
                ## Can be connect with "ingress" network
            # datemo_datemo.1.dean8edsp7ytoevagjnemb8bb
            server 10.255.0.6:8080;
                ## Can be connect with "datemo_default" network
            # datemo_datemo.1.dean8edsp7ytoevagjnemb8bb
            server 10.0.0.5:8080;
}
server {
    server_name [ip removed];
    listen 80 ;
    access_log /var/log/nginx/access.log vhost;
    location / {
        proxy_pass http://[ip removed];
    }
}
fraxture
  • 5,113
  • 4
  • 43
  • 83
  • 1
    FYI. What you put in [ip removed] is only an alias of the upstream, it is not an address at all. http://nginx.org/en/docs/http/ngx_http_upstream_module.html . So put there whatever name instead an IP that is not used – Robert May 17 '17 at 12:05
  • Actually, @Robert if I don't put my IP in there, I get a bad gateway error. – fraxture May 17 '17 at 15:04
  • ok.. but it seems some strange to me – Robert May 17 '17 at 15:06
  • The generation of these files is handled by nginx-proxy, which presumably is well thought-out. But what exactly seems strange to you? – fraxture May 17 '17 at 15:33
  • It's the fact of changing the upstream name that should not affect you. – Robert May 17 '17 at 17:06
  • I suspect that your Nginx container cannot access server 10.255.0.6:8080 nor server 10.0.0.5:8080 (some networking issue?) – Robert May 17 '17 at 17:10
  • 1
    I have the approach here working: https://www.thepolyglotdeveloper.com/2017/03/nginx-reverse-proxy-containerized-docker-applications/. So I think I will roll my own instead of trying to figure out why nginx-proxy doesn't work for me. – fraxture May 17 '17 at 17:15
  • I found the solution [here](https://stackoverflow.com/questions/23948527/13-permission-denied-while-connecting-to-upstreamnginx). may work for you :-) – dinu0101 Jul 27 '19 at 19:12

0 Answers0