By pirator
Hi,
My task is to setup a Nodejs app with Express/knex and Postgres. Unfortunately the “App” way did not work for me due to some self signed SSL certificate issue and technical support after a very long ping-pong game suggested to try the Droplet with Managed Database way.
I followed instructions here:
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04
to install NginX, then also here
to install nodejs and run the app. Now I have a Droplet with nodejs and nginx and it is possible to connect to the managed db via psql tool if I have ssh’ed to Droplet.
Now what I see is that I have nginx running and serving /var/www/html default page it puts there, but I can’t make it serve the nodejs server running on port 3000.
I ended up with the following config:
nano /etc/nginx/conf.d/website.conf
server {
listen 80;
server_name api.thewebsite.com;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://<IP address of this droplet>:3000;
}
}
Opening the IP in web browser shows nginx error code 502 Bad Gateway.
I am sure the nginx was restarted, it worked before the conf added and served the default html page. Also the nodejs server is running fine if I launch it manually.
What am I missing?
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!
Hi, First of all, check what address and port your app is listening on:
sudo netstat -tulpn
If your app is listening only on droplet’s public IP, ensure that you opened port TCP 3000 in a firewall.
If your app is listening on localhost (127.0.0.1) or on all droplet’s adresses (0.0.0.0/0), change your server block proxy pass directive:
proxy_pass http://localhost:3000;
In my opinion, the better approach is to have app listening on localhost rather than on public IP. In such case you do not have to open another port in firewall.
Hi, We achieved maximum replies, so I had to start a new answer.
Apparently, your app does not listen on any address:port at the moment. Did you install and configure pm2 to demonize your app ? I think you need to follow the steps of this tutorial again.
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.