LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-06-2024, 11:43 AM   #1
Jason.nix
Member
 
Registered: Feb 2023
Posts: 567

Rep: Reputation: 10
Post Configuring Nginx for Node.js


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 (?) open
Nginx 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.
 
Old 05-06-2024, 07:05 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,245

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
Well, I see logs in that nginx.conf. Anything interesting in those?
 
1 members found this post helpful.
Old 05-08-2024, 11:29 AM   #3
Jason.nix
Member
 
Registered: Feb 2023
Posts: 567

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by dugan View Post
Well, I see logs in that nginx.conf. Anything interesting in those?
Hello,
Thank you so much for your reply.
Problem solved. I must use the hostname in the YAML file for each container and use those hostnames instead of localhost in the Nginx configuration file.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rhel 2 node cluster: resources do not move to second node when node halted tapuhi Linux - Software 1 03-01-2015 10:41 AM
node recovery when the node becomes fault by using another node to replace it jerinc Linux - Wireless Networking 0 02-21-2014 05:44 PM
How to transfer the services from node 1 to node 2 ,if node 1 is directly turned off sankarg304 Linux - Server 1 12-12-2012 10:06 AM
JavaScript:: alert(node) shows null, but node != null taylor_venable Programming 1 05-01-2006 09:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration