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;
}
}