运行 Node.js 在 Google Compute Engine Debian 服务器上
Run Node.js on a Google Compute Engine Debian server
我在 Google Compute Engine 上有一个 debian 服务器 运行ning,主机像 example.com,我正在尝试 运行 node.js应用程序在目录中,例如 example.com/mynodeapp.
Node.js,debian 服务器上正确安装了 NPM。
我 运行宁 pm2 start main.js
从例子的根源。com/mynodeapp 和一切 运行宁 但是当我去例子时。com/mynodeapp ,我什么都没有,只有文件的索引。
Express.js 配置
main.js(条目)
var express = require('express')
var vhost = require('vhost')
express()
.use(vhost('example.com/mynodeapp', require('./dist/index').app))
.listen(8080)
dist/index.js
var express = require('express')
var app = express()
app.get('/', function(req, res) {
res.send('Hello World!');
})
exports.app = app
.listen(8080)
端口设置为 8080,因此您必须更改它或尝试 example.com:8080。
请注意,根据您的选择,您将 运行 陷入以下两个问题之一:端口 8080 可能未打开 – 您必须在防火墙中允许它。
如果您当前正在获取端口 80 上的文件列表,则还有一些其他服务器 运行ning(可能是来自标准 debian 安装的 apache 或 nginx)。您将必须停止该服务器以释放端口。
我在 Google Compute Engine 上有一个 debian 服务器 运行ning,主机像 example.com,我正在尝试 运行 node.js应用程序在目录中,例如 example.com/mynodeapp.
Node.js,debian 服务器上正确安装了 NPM。
我 运行宁 pm2 start main.js
从例子的根源。com/mynodeapp 和一切 运行宁 但是当我去例子时。com/mynodeapp ,我什么都没有,只有文件的索引。
Express.js 配置
main.js(条目)
var express = require('express')
var vhost = require('vhost')
express()
.use(vhost('example.com/mynodeapp', require('./dist/index').app))
.listen(8080)
dist/index.js
var express = require('express')
var app = express()
app.get('/', function(req, res) {
res.send('Hello World!');
})
exports.app = app
.listen(8080)
端口设置为 8080,因此您必须更改它或尝试 example.com:8080。
请注意,根据您的选择,您将 运行 陷入以下两个问题之一:端口 8080 可能未打开 – 您必须在防火墙中允许它。
如果您当前正在获取端口 80 上的文件列表,则还有一些其他服务器 运行ning(可能是来自标准 debian 安装的 apache 或 nginx)。您将必须停止该服务器以释放端口。