[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
一、业务描述:
最近在做一个电商的项目,里面有平台端和商家端以及用户端,那么这么多Vue项目如何部署到服务器呢?
二、部署
(1)首先在本地测试项目可以启动并且能正常运行。
(2)在项目中输入npm run build
此时会生成一个文件
(3)在服务器上安装Nginx,并将admin-web上传到服务器。
我上传的位置:
(4)修改Nginx文件,找到nginx.conf
三、如果此时有多个vue项目呢?
多加几个location即可
四、最后记得保存
:wq
五、重新启动Nginx
systemctl restart nginx
六:Nginx.conf的内容
server { listen 80; server_name localhost; #charset koi8-r; #access_log
logs/host.access.log main; location / { root html/dist/; index index.html
index.htm; try_files $uri $uri/ @router; index index.html; }
#对应上面的@router,主要原因是路由的路径资源并不是一个真实的路径,所以无法找到具体的文件 location @router { #
#因此需要rewrite到index.html中,然后交给路由再处理请求资源 rewrite ^.*$ /index.html last; }
location /admin { alias /usr/local/nginx/admin/dist; index index.html
index.htm; try_files $uri $uri/ @router; index index.html; }
#对应上面的@router,主要原因是路由的路径资源并不是一个真实的路径,所以无法找到具体的 location @router { #
#因此需要rewrite到index.html中,然后交给路由再处理请求资源 try_files $uri $uri/ @router; index
index.html; } #对应上面的@router,主要原因是路由的路径资源并不是一个真实的路径,所以无法找到具体>的文件 location
@router { # #因此需要rewrite到index.html中,然后交给路由再处理请求资源 rewrite ^.*$ /index.html
last; }