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; # 你的域名 <span class=token comment># 页面访问路径</span> location <span class=token operator>/</span> <span class=token punctuation>{<!-- --></span> root <span class=token operator>/</span>home<span class=token operator>/</span>dist<span class=token punctuation>;</span> <span class=token comment># 指向index.html的目录</span> try_files <span class=token variable>$uri</span> <span class=token variable>$uri</span><span class=token operator>/</span> <span class=token operator>/</span>index<span class=token punctuation>.</span>html<span class=token punctuation>;</span> <span class=token comment># 解决刷新报404的问题</span> index index<span class=token punctuation>.</span>html index<span class=token punctuation>.</span>htm<span class=token punctuation>;</span> <span class=token comment># 文件</span> <span class=token punctuation>}</span> <span class=token comment># 接口访问路径</span> location <span class=token operator>/</span>prod<span class=token operator>-</span>api<span class=token operator>/</span> <span class=token punctuation>{<!-- --></span> <span class=token comment># 解决跨域问题,区分接口调用路径,注意一定要加/</span> proxy_pass http:<span class=token operator>/</span><span class=token operator>/</span>api<span class=token punctuation>.</span>xxx<span class=token punctuation>.</span>com<span class=token operator>/</span><span class=token punctuation>;</span> <span class=token comment># 你的接口域名</span> <span class=token punctuation>}</span> <span class=token punctuation>}</span>
- 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