Hi. I wrote two differents apps in nodejs that run in two different ports. I would like to know how to configure nginx to redirect traffic to those apps.
The first app runs in the port 3000 and it is working fine. When the client type the url https://celr.com.br the traffic is going to the website.
The second app runs in the port 3001 and when the client tyep the url http://votolegal.celr.com.br it is directed to the same website, not to my second app.
The nginx conf file to the first domain is:
server {
root /var/www/celr.com.br/html;
index index.js index.html index.htm index.nginx-debian.html;
server_name celr.com.br www.celr.com.br;
location / {
# try_files $uri $uri/ =404;
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;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/celr.com.br/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/celr.com.br/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}server {
if ($host = www.celr.com.br) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = celr.com.br) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name celr.com.br www.celr.com.br;
return 404; # managed by Certbot
}
The nginx conf file to the domain votolegal.celr.com.br is:
server {
listen 80;
listen [::]:80;
server_name votolegal.celr.com.br;
root /var/www/celr.com.br/html;
location / {
proxy_pass http://localhost:3001;
}
}
I have already read a lot of documents showing how to configure that.
I don´t know what I am doing wrong.
Could someone help me?
Thanks in advance
Claudinei
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!
Here’s an example that should work in your case:
upstream app_server_one {
server 127.0.0.1:9000 fail_timeout=0;
}
upstream app_server_two {
server 127.0.0.1:7000 fail_timeout=0;
}
server {
listen 80 default_server;
server_name: example.com;
root /var/www//html;
index index.html index.htm;
# [snip...]
}
server {
listen 80;
server_name app1.example.com;
# [snip...]
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server_one;
}
}
server {
listen 80;
server_name app2.example.com;
# [snip...]
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server_two;
}
}
In the example, requests to example.com will serve static content from /var/www//html One to app1.example.com will serve a Django app listening on port 9000 and app2.example.com will serve the app listening on port 7000.
Just remember to update the ports and domains to match your own.
Let me know how it goes.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.