Article 6MKSR Configuring Nginx for Node.js

Configuring Nginx for Node.js

by
Jason.nix
from LinuxQuestions.org on (#6MKSR)
Hello,
I have two Node.js applications running on ports 3000 and 3001:
Code:# nc -zv 127.0.0.1 3000
localhost [127.0.0.1] 3000 (?) open
# nc -zv 127.0.0.1 3001
localhost [127.0.0.1] 3001 (?) openNginx configuration is as follows:
Code:server {
server_name server1;
listen 80;
error_log /var/log/nginx/error.system-default.log;
access_log /var/log/nginx/access.system-default.log;
charset utf-8;

location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

server {
server_name server2;
listen 80;
error_log /var/log/nginx/error.system-default.log;
access_log /var/log/nginx/access.system-default.log;
charset utf-8;

location / {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}I tried to see these applications:
Code:# curl localhost
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.25.4</center>
</body>
</html>What is wrong? If I use curl localhost:3000, then the file will be executed from Node.js and not Nginx!

Thank you.
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments