操作步骤

以访问路径端口号后面的上下文context为例子,最终的访问效果为:http:127.0.0.1:8098/context

1.vite.config.ts配置文件

base: '/context', 

2. 路由配置文件

const router = createRouter({
  history: createWebHistory('/context/'), // 与步骤1中的保持一致(注意斜杠)
  routes
})

3. Nginx配置文件

  1. 假设build后的静态文件夹采用默认的名称:dist
  2. 假设dist文件存放在Nginx服务器上的目录:/usr/local/nginx/www
  3. 假设访问的端口为:8098
    基于以上假设,则重启nginx后访问的路径为:
    http:127.0.0.1:8098/context
server {
        listen       8098;
        charset 	 utf-8;
        location /context {
        	alias /usr/local/nginx/www/dist;
        	index index.html;
       		try_files $uri $uri/ /index.html last;
    	}

	    # 下面的为Vue应用访问接口的配置(不受上下文的影响)
        location /xxx {
            proxy_pass http://ip:port;
        }
}
Logo

前往低代码交流专区

更多推荐