请教一下,关于 nginx 多个子目录反代的问题。

2022-10-20 01:04:33 +08:00
 binghe

现在多个服务运行在服务器上,想要达成如下效果,但是这个 nginx 不懂怎么配置了。。。 三个服务有两个是 python 的,一个是 go 的。

http://demo.abc.com/drive  --->  http://127.0.0.1:8855
http://demo.abc.com/avg   --->  http://127.0.0.1:8866
http://demo.abc.com/doc   --->  http://127.0.0.1:8877



server {
	listen 80;
	server_name demo.abc.com;
    
	root /var/www/html; #注释这个后也提示错误

	location /drive/ {
         rewrite ^/drive/(.*)$ /$1 break;  #也试着这样过,不知道是不是写错了,没有效果
         proxy_pass  http://127.0.0.1:8855;
   }
   
   location /avg/ {
         proxy_pass  http://127.0.0.1:8866;
   }
	
   location /doc/ {
         proxy_pass  http://127.0.0.1:8877;
   }    
    
}


log 日志,看日志,好像最大的问题就是这个 root 路径,如果把 root /var/www/html;这个注释掉,log 就是 /usr/share/nginx/html/assets/index.786270b3.js 这样的。


#349313: *1 open() "/var/www/html/assets/index.786270b3.js" failed (2: No such file or directory), client: 172.17.0.1, server: demo.abc.com, request: "GET /assets/index.786270b3.js HTTP/1.1", host: "demo.abc.com", referrer: "http://demo.abc.com/drive/"
```
2333 次点击
所在节点    NGINX
23 条回复
xiang0818
2022-10-24 15:40:54 +08:00
@Soutxx 卧槽
Soutxx
2022-10-24 17:18:17 +08:00
@xiang0818 自己加我,cG9zdGhp
lurenlym
2023-03-06 16:00:44 +08:00
https://github.com/RobinLinus/snapdrop
大佬们看看开源项目这个前端怎么解析带路径的,我想域名 www.example.com/snap 来访问这个项目

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/888264

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX