vue-router+nginx非根路径的配置方法

一、直接配置在根路径下

直接配置在根路径下,访问的时候只用输入http://1.15.179.248:8089(这边没有域名用ip代替),在nginx的配置如下

 

 二、非根路径配置

如果一个域名下有多个项目,那么使用根路径配置就不合适了,我们需要在根路径下指定一层路径,比如说

后台管理系统admin

http://1.15.179.248:8087/admin/

配置如下

 

 代码

 server {
        listen       8087;
        server_name  1.15.179.248;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location /admin {
            alias /data/admin-test/;  // 此处为admin项目放置的路径
            try_files $uri $uri/ /admin/index.html;
            index  index.html index.htm;
        }
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

注意要用alias不能用root

参考文章:https://www.php.cn/js-tutorial-406275.html

posted @ 2021-09-17 16:23  心向阳  阅读(1273)  评论(0编辑  收藏  举报