Nuxt3部署到服务器教程
2024-12-12 14:15:02
9
1
构建产物上传到服务器🤡
第一步、打包编译npm run build
第二步、将`.output`文件夹下所有文件打包上传到服务器项目目录cd /www/wwwroot/front/nuxt
tar -xzf package.tgz
# 删除 package.tgz
rm package.tgz
pm2 stop nuxt-blog
pm2 delete nuxt-blog
pm2 start ./server/index.mjs -i max --name nuxt-blog
第三步、修改nginx配置upstream nuxt-blog {
server 127.0.0.1:3000;
}
upstream api-server {
server 127.0.0.1:8001;
}
server {
listen 80;
server_name isxuch.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name isxuch.com;
# SSL 配置保持不变
ssl_certificate /usr/local/nginx/ssl/isxuch.com.pem;
ssl_certificate_key /usr/local/nginx/ssl/isxuch.com.key;
# API 请求的路由配置
location /open/ {
proxy_pass http://api-server;
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;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
}
# 前端页面的路由配置
location / {
proxy_pass http://nuxt-blog/;
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;
}
}
第四步、重启Nginxsudo nginx -t
sudo nginx -s reload
评论
文章评论--评论内容需审核不会在页面显示
禁止提交违法、欺诈、诽谤、骚扰、色情或其他有害内容