简体   繁体   English

如何在 linode 端口 80 上部署 nodejs 应用程序?

[英]How to deploy nodejs application on linode port 80?

I am using Linode instance (Ubuntu 20) to deploy my website.我正在使用 Linode 实例(Ubuntu 20)来部署我的网站。

Running the nginx server with default return IP_ADDRESS to the default nginx page and IP_ADDRESS:3000 to my actual application (when ofcourse it's running).运行 nginx 服务器,默认返回IP_ADDRESS到默认的 nginx 页面和IP_ADDRESS:3000到我的实际应用程序(当然它正在运行时)。

I want to allow the user to access my application directly using just IP_ADDRESS/ Now, for this I modified two things-我想允许用户直接使用 IP_ADDRESS/ 访问我的应用程序现在,为此我修改了两件事-

  1. /etc/nginx/sites-available/default - Changed default to root /root/APP_NAME/ /etc/nginx/sites-available/default - 将默认更改为 root /root/APP_NAME/
  2. /etc/nginx/nginx.cong - changed user from www-data to root /etc/nginx/nginx.cong - 将用户从 www-data 更改为 root

Now, what this does is serve my app.js file in plain text rather than actually serving the application irrespective of whether or not I have started my application using node app.js or not.现在,它的作用是以plain text形式提供我的 app.js 文件,而不是实际提供应用程序,而不管我是否使用node app.js启动了我的应用程序。

You don't need to change the default to root /root/APP_NAME.您无需将默认设置更改为 root /root/APP_NAME。 When you do that, NginX will serve files in your NodeJS app folder as static files.当您这样做时,NginX 会将您的 NodeJS 应用程序文件夹中的文件作为 static 文件提供。

What you need is to configure NginX to forward the request coming at port 80, to the NodeJS application.您需要配置 NginX 以将来自端口 80 的请求转发到 NodeJS 应用程序。

server {
    listen 80;

    location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass         http://127.0.0.1:3000;
    }
}

This tutorial explains step by step: https://hackernoon.com/configure-nginx-sa-reverse-proxy-for-your-nodejs-application-9tk032e8本教程一步一步解释: https://hackernoon.com/configure-nginx-sa-reverse-proxy-for-your-nodejs-application-9tk032e8

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

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