As I was following this tutorial: https://www.digitalocean.com/community/questions/setting-up-multiple-nodejs-applications-using-nginx-vitual-hosts
It doesn’t seem to work, as when i completed all steps and went to the sub domain it says this site cannot be reached, but if i just go to the ip it just shows this: https://imgur.com/a/CeY6iiu
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
To set up Nginx as a reverse proxy for multiple Node.js applications, each serving a different domain, you need to configure Nginx to listen on different
server
blocks for each domain and then proxy the requests to the respective Node.js applications running on different ports.Here’s a basic guide on how to achieve this:
Step 1: Start Node.js Applications on Different Ports
Let’s assume you have two Node.js applications you want to serve on
domain1.com
anddomain2.com
. Start each Node.js application on a different port. For example:domain1.com
) on port 3001domain2.com
) on port 3002Step 2: Install Nginx
If Nginx is not already installed on your server, you can install it using your package manager:
For Ubuntu/Debian:
For CentOS/RHEL:
Step 3: Configure Nginx
Create separate Nginx server blocks for each domain. This involves editing or creating files in
/etc/nginx/sites-available/
and then creating a symbolic link to them in/etc/nginx/sites-enabled/
.Create Nginx Server Block for Domain 1
Create a new configuration file:
Add the following configuration:
Create another configuration file:
Add a similar configuration, but change the server_name and proxy_pass:
Enable the Server Blocks
Create symbolic links to enable these configurations:
Step 4: Test and Restart Nginx
Step 5: DNS Configuration
Make sure the DNS records for
domain1.com
anddomain2.com
are correctly pointing to the IP address of your server where Nginx is running.Step 6: Firewall Configuration
If you have a firewall enabled, ensure that it allows HTTP (and HTTPS, if you’re using SSL) traffic:
For Ubuntu/Debian with UFW:
For CentOS/RHEL:
Step 7: Optional - Set up SSL (HTTPS)
Consider securing your applications with SSL certificates. You can use Let’s Encrypt to obtain free certificates. Certbot is a tool that can automate this process for you.
Hi there @selll,
I would recommend following the steps from this tutorial here instead:
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04#set-up-nginx-as-a-reverse-proxy-server
Then once you want to start a second Node.js application keep the following things in mind:
/etc/nginx/sites-available/default
to/etc/nginx/sites-available/example2.conf
and adjust the values there to match your second applicationFinally, restart Nginx as explained in the tutorial.
Let me know how it goes. Regards, Bobby