H5+Vue3编写官网,并打包发布到同一个域名下

背景

因为html5有利于搜索引擎抓取和收录我们网站更多的内容,对SEO很友好,可以为网站带来更多的流量,并且多端适配,兼容性和性能都非常不错,所以使用h5来编写官网首页。

因为用户个人中心可以通过官网跳转,不需要被浏览器抓取,所以为了提高开发效率,减少开发周期,使用vue来开发。

打包

vue3打包

1、 设置publicPath,这个路径将是你整个vue项目的根路径

2、建议创建一个config.js文件,存放你所有需要访问的外部链接,这样,当外部链接改变的时候,就不需要重新再打包,而是直接更改dist中的config.js(vue会在dist中也生成同一个config.js)

文件放到和inde.html同目录

并在index.html中引入

config.js内容

在页面中使用链接 window.ipConfig.你在config.js中设置的变量

3、npm run build

h5页面跳转vue页面

直接使用 /person/xxx,就能跳转到vue相应的而页面

/person是vue页面的根目录,xxx是你想要跳转的页面路径

配置nginx

对于h5编写的页面,有多少个就写多少个location

复制代码
server{
        listen  80;
        server_name  www.xxx.com; #你的域名 没有域名的也可以不配置

        location / {    #官网首页  h5编写的页面
                root /opt/xxx/website/html;
                index index_1.html index_1.htm;
        }
        location /download{       #h5编写的页面
                alias /opt/xxx/website/html;
                index download.html download.htm;

        }
        location /doc{            #h5编写的页面
                alias /opt/xxx/website/html/doc;
        }
        location /person{      //配置的vue路径
                alias /opt/xxx/website/html/dist;  #dist文件地址
                index index.html index.htm;     #dist index文件
                try_files $uri $uri/ /dist/index.html;   #加上这句可以避免页面刷新空白

        }
        location /xxxx/{        #配置的后端地址代理
                proxy_pass http://172.xxx.xxx.xxx:9634/xxx/;  #后端地址
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
        }
}

开启nginx

开启nginx就可以访问页面啦

相关推荐
longerxin20201 小时前
在 Linux 上使用 SCP 将文件传输到 Windows(已开启 SSH)
linux·运维·ssh
小二·4 小时前
前端监控体系完全指南:从错误捕获到用户行为分析(Vue 3 + Sentry + Web Vitals)
前端·vue.js·sentry
王正南4 小时前
kali-linux 虚拟机连接安卓模拟器
android·linux·运维·虚拟机连接模拟器·安卓模拟器,linux虚拟机
吳所畏惧5 小时前
Linux环境/麒麟V10SP3下离线安装Redis、修改默认密码并设置Redis开机自启动
linux·运维·服务器·redis·中间件·架构·ssh
yueguangni5 小时前
sysstat 版本 10.1.5 是 CentOS 7 的默认版本,默认情况下确实不显示 %wait 字段。需要升级到新版sysstat
linux·运维·centos
+VX:Fegn08955 小时前
计算机毕业设计|基于springboot + vue在线音乐播放系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
+VX:Fegn08956 小时前
计算机毕业设计|基于springboot + vue律师咨询系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·课程设计
萧曵 丶6 小时前
Linux 业务场景常用命令详解
linux·运维·服务器
豆是浪个7 小时前
Linux(Centos 7.6)命令详解:ps
linux·windows·centos
苏瞳儿7 小时前
vue2与vue3的区别
前端·javascript·vue.js