简体   繁体   English

从Digital Ocean Dropout外部访问节点应用程序还需要什么?

[英]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. 我们已经设置了一个在端口5000上运行的节点服务器。

In a newly created droplet , we have installed and started nginx . 在一个新创建的Droplet中 ,我们已经安装并启动了nginx To access the node app, we have changed the default port from 80 to 5000 in /etc/nginx/sites-enabled/default 要访问节点应用程序,我们已将/etc/nginx/sites-enabled/default的默认端口从80更改为5000

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

ufw is enabled ufw已启用

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 status所确认

sudo ufw状态

netstat -ntlp 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. 因此,我们将默认端口恢复为80。

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. 对于NodeJS和NGINX,我们将配置NGINX以侦听端口80 ,尽管我们希望使用proxy_pass将请求从Web服务器(NGINX)传递到该应用程序所在端口上的NodeJS应用程序。正在运行。 This will allow us to keep the port out of the URL. 这将使我们将端口保留在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). 使用当前配置,NGINX将在端口5000上进行侦听,这将阻止应用程序在同一端口上侦听(反之亦然)。

There is an excellent guide that covers setting up NodeJS + NGINX -- this specific part is the most important: 有一个很棒的指南涵盖了设置NodeJS + NGINX的工作-这一部分是最重要的:

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 https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04#set-up-nginx-as-反向代理服务器

The above covers how we'd go about setting up the Server Block :-) 上面介绍了如何设置服务器块:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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