nginx 部署多个vue项目, 静态资源404

nginx 部署多个vue项目, 静态资源404

1: 路由配置

const RouterConfig = {
    base: '/aa/',
    mode: 'history',
    routes: [
		...
	]
};

2: vue.config.js配置

module.exports = {
    publicPath: '/aa/',
    devServer: {
        host: '0.0.0.0',
        ...
    }
}

3: nginx配置方法1

server {
	listen       80;
	server_name  localhost;
	location /aa/ {
	    if (!-e $request_filename) {
	        rewrite ^/(aa)/(.+)$ /$1/index.html last;
	        break;
	    }
	    alias /usr/local/java/aa/;
	    index index.html;
	}
	location /bb/ {
	    if (!-e $request_filename) {
	        rewrite ^/(bb)/(.+)$ /$1/index.html last;
	        break;
	    }
	    alias /usr/local/java/bb/;
	    index index.html;
	}
}

nginx配置方法2

server {
	listen       80;
	server_name  localhost;
	location /aa/ {
	    try_files $uri $uri/ @rewrites; 
	    alias /usr/local/java/aa/;
	    index index.html; 
	}
	location @rewrites {
	    rewrite ^/(aa)/(.+)$ /$1/index.html last;
	}
	location /bb/ {
	    try_files $uri $uri/ @rewrites1; 
	    alias /usr/local/java/bb/;
	    index index.html; 
	}
	location @rewrites1 {
	    rewrite ^/(bb)/(.+)$ /$1/index.html last;
	}
}

版权声明:本文为weixin_40502536原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。