502 Bad Gateway/ failed (111: Connection refused) while connecting to upstream

18,740

I used this configuration in my NGINX config where appsrv is the name of the docker-compose.yml service for the fastcgi image

server {

    #listen 80 default_server;
    listen 80;
    #server_name xxxxxxxxx.com;
    index index.php index.html;
    root /var/www/html;

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info  ^(.+\.php)(/.+)$;
        fastcgi_index            index.php;
        fastcgi_pass             appsrv:9000;
        include                  fastcgi_params;
        fastcgi_param   PATH_INFO       $fastcgi_path_info;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    client_max_body_size 200M;

}
Share:
18,740

Related videos on Youtube

KArneaud
Author by

KArneaud

I websites, games and rich interactive applications (RIAs). I am proficient in PHP 4/5, MySQL, JQuery. use and develop for Web Services such as Facebook, Instagram, Twitter, Google and Youtube. I develop using frameworks such as VueJS, jQuery, PugJS, Sass, SlimPHP, Laravel, Idiorm and Paris, and Wordpress. I also worked using Adobe Illustrator, Adobe Photoshop, Git and Docker software applications.

Updated on September 18, 2022

Comments

  • KArneaud
    KArneaud over 1 year

    I have the following docker-compose xml

    web:
      build: nginx/.
      container_name: nginx
      ports:
        - "80:80"
      links:
        - "openchain"
      restart: always
    wallet:
      build: wallet/.
      container_name: wallet
      ports:
        - "81:81"
      restart: always
      read_only: false
      volumes:
        - ./www:/usr/share/nginx/html:rw
      working_dir: /user/share/nginx/html
    openchain:
      build: openchain/.
      ports:
        - "8080"
      volumes:
        - ./data:/openchain/data
      restart: always
    

    And the following conf for web and wallet respectively

    worker_processes 4;
    
    events { worker_connections 1024; }
    
    http {
        server {
            listen 80;
    
            location / {
                proxy_pass http://127.0.0.1:8080/;
    
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
            }
        }
    }
    

    and

    worker_processes 4;

    events { worker_connections 1024; }

    http {

    server {
        listen 81;
    
        location / {
            root /usr/share/nginx/html;
        }
    }
    

    }

    when I run docker ps I get

        05e351c8f8db        openchain_web         "nginx -g 'daemon off"   5 seconds ago       Up 5 seconds        0.0.0.0:80->80/tcp, 443/tcp    nginx
        e7401ea7c5bc        openchain_wallet      "nginx -g 'daemon off"   5 seconds ago       Up 5 seconds        80/tcp, 443/tcp,
    0.0.0.0:81->81/tcp   wallet
        40439fdb1c69        openchain_openchain   "dotnet openchain.dll"   5 seconds ago       Up 5 seconds        0.0.0.0:32774->8080/tcp        openchain_openchain_1
    

    But when I try to access the port openchain_openchain via proxy openchain_web I get the subject error

    I'm new to docker so I'm not sure I'm proxying correctly with the nginx

    Can you tell me what I did wrong?

    P.S. I can access wallet just fine

    • Michael Hampton
      Michael Hampton over 5 years
      As the new answer states, you must connect to the name of the other container, not to 127.0.0.1.
  • Michael Hampton
    Michael Hampton over 5 years
    Right. You have to connect to the name of the other container, not to 127.0.0.1.