Nginx 支持单域名多 Vue 服务配置备忘

栏目: JavaScript · 发布时间: 6年前

内容简介:仅仅通过上述配置,在访问新版前端时,会遇到资源文件无法找到的问题。此时,可以通过对新版前端

最近开发时,遇到需要使用同一域名承载多个前端项目的场景,具体需求如下:

/v2
/api
/

1. Nginx 配置内容

server {
    listen       80;
    listen       [::]:80;
    server_name  _;

    server_name_in_redirect off;
    proxy_set_header Host $host;

    location /api {
        proxy_pass http://0.0.0.0:0000;
    }

    location / {
        index  index.html;
        root /path/to/main/web/app;
    }

    location /v2 {
        index  index.html;
        root /path/to/v2/web/app;
    }
}

2. 修改 publicPath 配置

仅仅通过上述配置,在访问新版前端时,会遇到资源文件无法找到的问题。

此时,可以通过对新版前端 vue.config.js 文件中的 publicPath 进行配置,以规避这一问题( 注:该方法仅适用于 Vue-Cli 3.x 构建的项目 ):

module.exports = {
    ...
    
    publicPath: '/v2/',
    
    ...
};

参考链接

  1. Understanding the difference between the root and alias directives in Nginx
  2. Can't get two single page applications to run together on one server using nginx

以上所述就是小编给大家介绍的《Nginx 支持单域名多 Vue 服务配置备忘》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Software Paradigms

Software Paradigms

Stephen H. Kaisler / Wiley-Interscience / 2005-03-17 / USD 93.95

Software Paradigms provides the first complete compilation of software paradigms commonly used to develop large software applications, with coverage ranging from discrete problems to full-scale applic......一起来看看 《Software Paradigms》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具