首页 > 解决方案 > Nuxt.js Universal 项目的 nginx 服务器配置到底应该是什么?

问题描述

使用 Nginx 在 Ubuntu 上部署我的 nuxt.js 项目时遇到了很大的麻烦;

Ubuntu 18.04 + nginx
Nuxt.js 2.3.2 (universal mode)

所以也许有人可以帮助我解决我的问题)

我将在下面描述围绕此问题的所有内容:

我的 nuxt.conf 构建部分

我的 nginx 配置

然后我在 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"

所以现在我不知道这有什么问题。请帮帮我。

标签: nginxvue.jsnuxt.jspm2nuxt-edge

解决方案


似乎 Nginx 尝试在 IPv6 环回 [::1] 上进行连接,而 nodejs 可能只是在侦听 IPv4。

尝试设置127.0.0.1而不是localhost


推荐阅读