稷然如此

  • 首页
  • 文章分类
    • AI
    • Android
    • Java
    • Shell
    • Vue
    • C#
    • Python
    • 数据库
    • 组件
    • 其他
    • Game
  • 常用命令
    • Docker
    • Git
    • Linux
  • 操作系统
    • CentOS
    • Ubuntu
    • Windows
    • Kylin
  • 工具
    • IntelliJ IDEA
    • Visual Studio Code
稷然如此
不积跬步,无以至千里
  1. 首页
  2. 文章分类
  3. 其他
  4. 正文

Nginx 配置同一端口不同访问前缀访问不同项目

2025年10月14日 47点热度 1人点赞
server {
	listen       6013;
	server_name  localhost;

    location / {
        root /etc/nginx/html/home;
        index index.html index.htm;
        try_files $uri $uri/ /index.html;
    }

    location /home {
        alias /etc/nginx/html/dist;
        index index.html index.htm;
        try_files $uri $uri/ /home/index.html;
    }

	location /admin-api {
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_read_timeout 3000m;
		proxy_pass_header Set-Cookie;
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-Host $host;
		proxy_pass http://127.0.0.1:6014;
	}

	location /app-api {
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_read_timeout 3000m;
		proxy_pass_header Set-Cookie;
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-Host $host;
		proxy_pass http://127.0.0.1:6014;
	}

	#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;
	}
}
注意:
通过访问前缀 /home 访问的项目,需要 vite 打包时,增加 base 参数,使所有引用资源都是这样的: src="/home/xxx.js",这样才能访问,否则会报错:Failed to load module script: Expected a JavaScript-or-Wasm module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
标签: Nginx
最后更新:2025年10月14日

Akim

犇 骉 Java、C#、Python、Go、Android、MiniProgram、Bootstrap、Vue2

点赞
< 上一篇

Copyright © 2025 aianran.com All Rights Reserved.

免责申明 | 隐私政策 | 服务条款 | 关于我们

黔ICP备2023008200号-1

贵公网安备 52010202003594号