首页 > 解决方案 > 将简单的 nodejs 应用程序部署到我的 uni linux vm

问题描述

我有一个从我的 uni 访问的 vm linux 机器,我必须向它部署简单的 nodejs 应用程序。我可以对 vm 机器和所有东西进行 ssh,并且我已经在其上安装了 Nginx,但是每当我尝试运行一个简单的“hello world”节点应用程序并从家里的浏览器访问它时,我都会被重定向到其他在线站点,或者我没有得到任何响应。

这是我的 Nginx 配置文件

# the nginx server instance

server {

listen 80;

listen [::]:80;

server_name fff.com www.fff.com;

access_log /var/log/nginx/yourdomain.com.log;



# pass the request to the node.js server with the correct headers

# and much more can be added, see nginx config options

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://app_fff/;

proxy_redirect off;

}

}

和我的 hello world 应用

var http = require('http');



http.createServer(function (req, res) {

res.writeHead(200, {'Content-Type': 'text/plain'});

res.end('Hello World\n');

}).listen(3000, "127.0.0.1");

console.log('Server running at http://127.0.0.1:3000/');

我运行该应用程序,我可以从另一个 ssh 卷曲它,但是当我转到 fff.com 时,我要么无法访问网站,要么被重定向到普通网站。

我究竟做错了什么???如何在我的 uni linux vm 上键入 host 这个愚蠢的应用程序并从家里的浏览器访问它?

标签: node.jsnginxweb-deployment

解决方案


推荐阅读