nginx - Nuxt.js Universal 项目的 nginx 服务器配置到底应该是什么?
问题描述
使用 Nginx 在 Ubuntu 上部署我的 nuxt.js 项目时遇到了很大的麻烦;
Ubuntu 18.04 + nginx
Nuxt.js 2.3.2 (universal mode)
所以也许有人可以帮助我解决我的问题)
我将在下面描述围绕此问题的所有内容:
然后我在 ssh 中运行这个命令
sudo npm run build
sudo pm2 start npm --name "nuxt" -- start
现在服务器正在监听 localhost:3000,正如我在 package.json 中所写
毕竟,当我打开我的网站时,我在控制台中遇到了 500 错误。 服务器错误
nginx 错误日志
2018/11/26 04:48:42 [error] 15032#15032: *5773 upstream prematurely closed connection while reading response header from upstream, client: 173.267.244.9, server: example.com, request: "GET /seller HTTP/1.1", upstream: "http://127.0.0.1:3000/seller", host: "example.com"
2018/11/26 04:48:42 [error] 15032#15032: *5773 connect() failed (111: Connection refused) while connecting to upstream, client: 173.267.244.9, server: example.com, request: "GET /seller HTTP/1.1", upstream: "http://[::1]:3000/seller", host: "example.com"
2018/11/26 04:48:43 [error] 15032#15032: *5773 no live upstreams while connecting to upstream, client: 173.267.244.9, server: example.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://localhost/favicon.ico", host: "example.com", referrer: "http://example.com/seller"
所以现在我不知道这有什么问题。请帮帮我。
解决方案
似乎 Nginx 尝试在 IPv6 环回 [::1] 上进行连接,而 nodejs 可能只是在侦听 IPv4。
尝试设置127.0.0.1
而不是localhost
推荐阅读
- nativescript - 仅允许 TextField 中的数值
- node.js - 特定函数运行时阻塞事件循环
- json - 如何从 JSON 对象获取数据到 Angular?
- c - 如何用前导零填充整数打印?
- angularjs - ng-options 如何在没有控制器的情况下工作?
- javascript - Internet Explorer 8 - 新 Map() 替换
- python-3.x - SelectKBest 将分数作为 nan 值
- python - 从字典到列表的日期
- reactjs - Model.confirm () 不允许使用“This”
- c - 如何调试从 Go 代码到 C 代码的调用中的 memleak?