简体   繁体   中英

What else is required to access a node app from outside a Digital Ocean droplet?

We have set up a node server which runs on port 5000.

In a newly created droplet , we have installed and started nginx . To access the node app, we have changed the default port from 80 to 5000 in /etc/nginx/sites-enabled/default

server {
        listen 5000 default_server;
        listen [::]:5000 default_server;

ufw is enabled

sudo ufw enable

Also the port is enabled

sudo ufw allow 5000/tcp

Also, tried this way too:

sudo ufw allow 5000

As confirmed with sudo ufw status

sudo ufw状态

netstat -ntlp

netstat -ntlp

Also the app is configured to listen on the public interface

const server = app.listen(process.env.PORT || 5000, '0.0.0.0', () => {
    console.log('Express server listening on port %d in %s mode', server.address().port, app.settings.env);
});

However, not even the default port was responding. Hence, we reverted to 80 as the default port.

What else is required to access node app outside of the droplet?

When it comes to NodeJS and NGINX, we'll want to configure NGINX to listen on port 80 , though we'll want to use proxy_pass to pass the request from the web server (NGINX) to the NodeJS application on the port that the application is running on. This will allow us to keep the port out of the URL.

With the current configuration, NGINX would be listening on port 5000 which would prevent the application from being able to listen in on the same port (or vice versa).

There is an excellent guide that covers setting up NodeJS + NGINX -- this specific part is the most important:

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

The above covers how we'd go about setting up the Server Block :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM