I have a NodeJS application that is in dockerisation, and I have a NGINX dock container that balances workloads between NodeJS processes in docker containers. I can collapse both NodeJs servers successfully, but NGINX cannot find upstream servers.
Here is nginx conf:
upstream app {
least_conn; # Use Least Connections strategy
server 127.0.0.1:3000; # NodeJS Server 1
server 127.0.0.1:3001; # NodeJS Server 2
}
server {
listen 80;
server_name example.com;
access_log /var/log/nginx/example.com-access.log;
error_log /var/log/nginx/example.com-error.log error;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
location ~* (images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) {
root /usr/share/nginx/html;
}
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://app/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /mobile-api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://www.goodrx.com/mobile-api;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Then I run containers to bind node 3000 and 3001 containers and port 80 of the nginx container bind. When twisting 127.0.0.1:80 I get a Bad request, but twisting 127.0.0.1haps000 and 127.0.0.1haps001 works. Any ideas what could be wrong with NGINX proxying?
source
share