Nuxt 没有创建 dist 目录

Nuxt not creating dist directory

我使用 docker-compose 构建和 运行 一个 SSR Nuxt.JS 应用程序。 Web 服务器是 nginx.

我无法对 运行 此应用程序使用 nginx 反向代理,因为目录 dist 未在 /app/ 中创建。这是我的 Dockerfile:

FROM node:14.17.0-alpine
WORKDIR /app
COPY . /app
RUN apk add python make g++
RUN yarn install
RUN yarn build
ENV HOST 0.0.0.0
ENV PORT 3000
ENV NODE_ENV production
EXPOSE 3000
CMD [ "yarn", "start" ]

它不起作用。但是如果我 运行 这个命令在我的 docker 主机路径 /home/path/project-1/ (路径 Nuxt.JS 文件存在):

yarn start

我可以通过以下方式暂时查看应用程序:

http://ip:3000

我搜索并尝试了一些解决方案,但 none 有效(不幸的是)。

这是我在终端中 运行 yarn start 时的日志:

yarn run v1.22.11
$ nuxt start
ℹ [HPM] Proxy created: /api/  -> https://api.site.com/api
ℹ [HPM] Proxy rewrite rule created: "^/api/" ~> ""

   ╭───────────────────────────────────────────╮
   │                                           │
   │   Nuxt.js @ v2.14.3                       │
   │                                           │
   │   ▸ Environment: production               │
   │   ▸ Rendering:   server-side              │
   │   ▸ Target:      server                   │
   │                                           │
   │   Memory usage: 32.7 MB (RSS: 105 MB)     │
   │                                           │
   │   Listening: http://ip:3000/   │
   │                                           │
   ╰───────────────────────────────────────────╯

运行ning 有什么问题?

我无法将其代理传递给 nginx 的原因是没有文档根目录。如果我在 root 指令的开头使用 #,我在 nginx:

中使用此错误
2021/10/14 12:02:29 [error] 25#25: *180 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: my_ip, server: app.site.com, request: "GET / HTTP/1.1", host: "app.site.com"
2021/10/14 12:02:29 [error] 25#25: *181 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: my_ip, server: app.site.com, request: "GET /favicon.ico HTTP/1.1", host: "app.site.com", referrer: "https://app.

更新 1

正如 kissu 所说,这是 nuxt.config.js 中的相关块:

  target: 'server',
  server: {
    port: 3000, // default: 3000
    host: '0.0.0.0', // default: localhost
  },

使用 yarn build 和定位 /app/.nuxt 解决了这个问题。