【发布时间】:2017-06-02 03:08:12
【问题描述】:
我在 DigitalOcean 的 Ubuntu 机器上创建了两个 node.js 实例。 两者都使用不同的端口侦听 localhost。 然后通过 curl http:\localhost:${port} 进行测试。两者都有效。
然后我将它们添加到 /etc/nginx/site-available/default
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
proxy_pass http://localhost:8837;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /app {
proxy_pass http://localhost:9837;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
只有 http://${ip_address}:${port}/ 有效。
http://${ip_address}:${port}/app 返回 “无法获取 /app”
我在 node.js 中使用 express 是不是问题出在哪里?
【问题讨论】:
-
你能发布你的 nginx 错误日志吗?它们常见于
/var/log/nginx/error.log。 -
感谢 Oliver,我找不到 error.log,因为我通过复制 /etc/nginx/sites-available/ 中的默认值将应用程序移动到另一个端口,并监听另一个端口。
标签: node.js nginx location digital-ocean