ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux部署vue项目

2022-05-09 00:04:23  阅读:343  来源: 互联网

标签:index vue dist 部署 访问 html https Linux com


摘自: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

标签:index,vue,dist,部署,访问,html,https,Linux,com
来源: https://www.cnblogs.com/duende99/p/16247579.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有