OBJUI

Docker 高效部署 Nuxt3 应用指南

2025-03-12 20:21:32 47

1、Nuxt3打包

npm run build

2、在服务器创建目录 blog

3、把以下文件上传到服务器目录 blog

.output
package.json
.env

4、创建docker-compose.yml

version: "3"

services: app: container_name: blog build: . volumes: - ./:/app restart: always ports: - "3000:3000"

5、创建Dockerfile

FROM node:18-alpine

WORKDIR /app

COPY package*.json ./ RUN npm install

COPY . .

RUN npm run build

EXPOSE 3000

CMD [ "node", ".output/server/index.mjs" ]

6、创建容器

docker-compose up  -d --build

7、宿主服务器创建nginx服务,并创建站点 blog.objui.com

server {
    listen 80;
    server_name blog.objui.com;

# 重定向到HTTPS
return 301 https://\$host\$request_uri;

}

server { listen 443 ssl; server_name blog.objui.com;

ssl_certificate /etc/letsencrypt/live/blog.objui.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blog.objui.com/privkey.pem;

# SSL配置
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:...;

location / {
    proxy_pass http://localhost:3000;
    proxy_set_header Host \$host;
    proxy_set_header X-Real-IP \$remote_addr;
    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto \$scheme;
}

}





更多精彩,请关注公众号

微信公众号