node.js - 将简单的 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 这个愚蠢的应用程序并从家里的浏览器访问它?
解决方案
推荐阅读
- python - 从python中的嵌套json数组中提取数据
- javascript - 在数组中切片节点
- reactjs - 您可以在条件内使用 useState 中的“setter”吗?
- ios - 删除后如何重新安装 ProjectUITests?
- google-sheets - 使用 Google 表格公式从具有多种类型的未排序数据集中获取每种类型的 MIN 值
- python - TKinter 窗口在 Python 中没有响应
- elixir - 当日期位于 DST 的不同侧时使用 Timezone.convert
- javascript - 如何在 Javascript 中每隔几秒调用一次函数?
- node.js - 等待关键字不停止执行
- jenkins - 如何获取或将其他工作构建持续时间传递给当前工作