此文适用于 vue-cli 创建的 vue 项目
可能不适用于 vue-vite 脚手架创建的项目
先按我另一篇随笔搭建生产环境https://blog.csdn.net/weixin_38848757/article/details/114325932
npm run build
将打包好的生产代码上传至服务器,假设目录为/usr/local/projects/project_1/dist,配置nginx.conf
# find /usr/local -name nginx.conf vim /usr/local/nginx/conf/nginx.conf
将server=>location=>root配置项改为 /usr/local/projects/project_1/dist ,其他不要动参考https://www.cnblogs.com/fengyuexuan/p/11471269.html
server { listen xxxx; # 8080 server_name xxx.xxx.xxx.xxx; # 139.123.1.16 location / { root /usr/local/projects/project_1/dist; try_files $uri $uri/ @router; index index.html index.htm; } }
(重新)启动 nginx https://blog.csdn.net/weixin_38848757/article/details/114325932
使用 docker 部署可以参考https://blog.csdn.net/SGAFPZys/article/details/80863509