我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" ]
這是行不通的。但是如果我在我/home/path/project-1/的 docker主機路徑(路徑 Nuxt.JS 檔案存在)中運行這個命令:
yarn start
我可以通過以下方式暫時查看應用程式:
http://ip:3000
我搜索并嘗試了一些解決方案,但沒有一個奏效(不幸的是)。
這是我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/ │
│ │
╰───────────────────────────────────────────╯
跑步有什么不好?
我不能代理將它傳遞給 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
},
uj5u.com熱心網友回復:
使用yarn build和定位/app/.nuxt解決了這個問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/323899.html
上一篇:NGINXnet::ERR_CONNECTION_REFUSED與AWS中的PM2ReactJS前端和Express后端
