Linux部署vue项目

摘自:https://blog.csdn.net/qq_24378737/article/details/119828363

原理:vue打包编译后的文件就是一套纯静态页面,在本地能直接访问index.html,放到服务器任意目录也能直接访问,通过Nginx反向代理用域名指向服务器的index.html就可以正常访问了。

1. vue本地打包编译生成dist文件夹
2. 上传到服务器任意目录(例如:/home/dist)
3. Nginx配置文件,下面是贴出一个的简单例子

	server
    {
        listen       80;						 # 监听的端口 http是80,https是443 
        server_name  www.xxx.com;				 # 你的域名

# 页面访问路径
location / {
root /home/dist; # 指向index.html的目录
try_files $uri $uri/ /index.html; # 解决刷新报404的问题
index index.html index.htm; # 文件
}

# 接口访问路径
location /prod-api/ { # 解决跨域问题,区分接口调用路径,注意一定要加/
proxy_pass http://api.xxx.com/; # 你的接口域名
}
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

相关博客参考:
https://www.cnblogs.com/heyiping/p/13645198.html
https://www.cnblogs.com/zouzou-busy/p/11827511.html

posted on 2022-05-08 23:40  duende99  阅读(743)  评论(0)    收藏  举报