Sunday 21 May 2017

Why does Nginx not find my upstream NodeJS server?

My Nginx configuration, which runs on Linux Mint 18 looks like this

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections  1024;
}

http {

    upstream nodeapp {
        server 192.168.99.101:3000;
    }

    server {

        listen       8080;
        server_name  hostname;

        proxy_redirect                          off;
        proxy_set_header Host                   $host;
        proxy_set_header X-Real-IP              $remote_addr;
        proxy_set_header X-Forwarded-Host       $host;
        proxy_set_header X-Forwarded-Server     $host;
        proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";

        location /nodeapp {
          proxy_pass http://nodeapp/;
        }        
    }
}

I have a docker container which hosts a nodejs express server via docker machine at 192.168.99.101:3000 (on the same machine). 192.168.99.101:3000 is directly accessible from my web browser and it sends a successful response back.

However when I try to access the same from nginx http://localhost:8080/nodeapp (as per the aforementioned configuration), I get a 404.

I have confirmed that Nginx service started properly via systemctl status nginx.service. However when http://localhost:8080/nodeapp is requested, I can see that the following command

tail /var/log/nginx/error.log

displays the error message

*26 open() "/usr/share/nginx/html/nodeapp" failed (2: No such file or directory), client: 127.0.0.1, server: , request: "GET /nodeapp HTTP/1.1", host: "localhost:8080"

It looks to me like the request is not getting proxyed. Any thoughts why? Thanks in advance.



via Harindaka

No comments:

Post a Comment