项目的入口文件index.html直接在服务器访问地址的根目录下,即项目独占一个端口
vue中配置保持不变
nginx中配置如下:
server {
listen 8899;
server_name localhost;
location / {
try_files $uri $uri/ /index.html;
}
}
第二种是 针对项目放在子级目录的情况。
# 打包配置 config-index.js 修改路径:
assetsPublicPath: './';
# 前端路由配置 router.js:
const router = new VueRouter({
mode: 'history',
base: '/hello',
routes
})
这里一定要一个加一个base;与项目子级目录名同步
nginx 配置:
server {
listen 8088;
server_name xxx.com; # localhost修改为您证书绑定的域名。
location /hello{
try_files $uri $uri/ /hello/index.html;
}
}
最终访问xxxxx:8088/hello
一个nginx 配置多个端口,多个子域名
server {
listen 8082;
listen 8088;
server_name localhost; # localhost修改为您证书绑定的域名。
location /hello {
try_files $uri $uri/ /hello/index.html;
}
location /hello2 {
try_files $uri $uri/ /hello2/index.html;
}
来源:oschina
链接:https://my.oschina.net/u/4394481/blog/3321394