By selimmorlevi
So, I wanted to have 2 different subdomains work on the same droplet. Added them through digitalocean console. Then created folders for both of them using node.js and express and set up ports for each of them by modifying /home/subdomain/bin/www file as follows:
var port = normalizePort(process.env.PORT || '3002');
I followed this guideand setup nginx for both domains. Then I used pm2 start www for both sites.
Both domains are working, only problem is that I have to type the port number in the url (ex: subdomain.domain.net:3001), otherwise both domains redirect to the 2nd domain.
My 1st website’s nginx config file.
server {
server_name subdomain.domain.net;
listen 80;
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://my droplet's IP:3001;
proxy_redirect off;
}
}
My 2nd website’s nginx config file.
server {
server_name subdomain.domain.net;
listen 80;
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://my droplet's IP:3002;
proxy_redirect off;
}
}
How can I get both domains working so that I don’t have to type the port number in the url?
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!
Hello friend!
You are definitely thinking on the right path here to make this function correctly. My instinct is telling me that there is either an error with the Nginx config, or one isn’t being loaded for some reason. You can’t really trace an error here because as far as the web server knows it’s functioning as configured.
So I suppose my questions are:
Kind Regards, Jarland
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.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.