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

时间:2021-09-17
本文章向大家介绍vue-router+nginx非根路径的配置方法,主要包括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

原文地址:https://www.cnblogs.com/qdlhj/p/15305205.html