Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持同一域名按照不同路径设置不同的上游服务器 #131

Open
allen12921 opened this issue Jul 5, 2023 · 11 comments
Open
Labels
enhancement New feature or request

Comments

@allen12921
Copy link

有时候由于域名紧缺我们会通过不同的访问路径来对应不同的后端服务,例如:
test.com/api,test.com/oauth 这两个路径分别对应api和oauth服务,目前的”防护站点“一个域名只能设置一个上游服务器,无法满足此场景,希望能在添加站点的页面增加一个路径选项。

@luweijun1992
Copy link

可以使用以下:终端用户 --> WAF --> Nginx(自定义路径转发到不同上游)--> 站点

@zclaiqcc zclaiqcc added the enhancement New feature or request label Jul 5, 2023
@zclaiqcc
Copy link
Collaborator

zclaiqcc commented Jul 5, 2023

理论上现在可以自己 DIY 一个出来,大概的步骤是:

  1. 在 resources/nginx/site-enabled/ 下增加 IF_backend_custom 文件,随便 copy 一个其他的 IF_backend_X 文件
  2. 修改 location 为匹配 api 或者 oauth
  3. 修改 upstream,把 backend_1 改名为 backend_custom,把 server 换成 location 对应的业务
  4. (可选)删掉 t1k_append_header SL-CE-SUID 1; 这一行,站点的检测模式跟这个字段有关系,不传就按照「防护」模式生效

这个 IF_backend_custom 不会被覆盖,所以师傅可以随意写。总之就是自己配置 nginx,页面上看不到这个站点,但是底层能转发到雷池的检测服务,同时会记录日志和统计(有点嵌入式模式的感觉)

@allen12921
Copy link
Author

allen12921 commented Jul 7, 2023

@zclaiqcc
这样并不可行,配置不会生效,因为两个配置里都是相同的server name,我添加配置reload nginx得到下面的提示
nginx: [warn] conflicting server name "test.com" on 0.0.0.0:8888, ignored

@microqs
Copy link

microqs commented Jul 22, 2023

渴望此功能

@beimingxue123
Copy link

这个功能等好久了

@upbeat-backbone-bose
Copy link

渴望此功能+1,今天刚在微信群问过,不想再因为个例套娃多增加一层nginx了

@lendy98
Copy link

lendy98 commented Nov 23, 2023

确实是很实用的功能。
强烈建议增加。
另外再增加个本地目录映射就更好了。

可以考虑开发自定义内容,自己将需要的内容往里面写,放在对应的 server 下。这样好多需要的功能都不用再开发。
微信图片_20231123095056

@upbeat-backbone-bose
Copy link

upbeat-backbone-bose commented Nov 23, 2023

确实是很实用的功能。 强烈建议增加。 另外再增加个本地目录映射就更好了。

可以考虑开发自定义内容,自己将需要的内容往里面写,放在对应的 server 下。这样好多需要的功能都不用再开发。 微信图片_20231123095056

您这个截图来源是哪里的呀?盲猜Nginx Proxy Manager? @lendy98

@lendy98
Copy link

lendy98 commented Nov 23, 2023

确实是很实用的功能。 强烈建议增加。 另外再增加个本地目录映射就更好了。
可以考虑开发自定义内容,自己将需要的内容往里面写,放在对应的 server 下。这样好多需要的功能都不用再开发。 微信图片_20231123095056

您这个截图来源是哪里的呀?盲猜Nginx Proxy Manager? @lendy98

你这猜它干嘛,确实从Proxy角度,他绝对还是强大的。 他有模板能直接修改,我就把 safeline 的 t1k 功能 放他那去了,安全过滤,黑白名单都能用,就是 人机验证用不了。把 [safeline-tengine] 停了。

反过来说safeline的这个问题:
include /etc/nginx/custom_params/backend_36; 这个直接放在 server 下,自己直接修改这个文件好了,对应 有没有其他include,修改 /etc/nginx/sites-enabled/IF_backend_36 又会被覆盖。
微信图片_20231123105038

@lendy98
Copy link

lendy98 commented Nov 23, 2023

我自己曲线救国成果,custom_confs目录为 server里面增加内容。

做个脚本定时1分钟运行一次,运行脚本如下:
#!/bin/bash target_directory="/data/safeline/resources/nginx/sites-enabled" found_file=0 find "$target_directory" -type f -name IF_backend_* -mmin -60 | while read file do echo "Edit $file" index=$(echo "$file" | awk -F 'IF_backend_' '{print $2}') sed -i "s/location ^~ \/ {/include \/etc\/nginx\/custom_confs\/backend_$index;\n location ^~ \/ {/g" "$file" touch -m -t 200703311230.09 "$file" touch /data/safeline/resources/nginx/custom_confs/backend_$index found_file=1 done if [ $found_file -eq 1 ]; then echo "Find file" docker exec safeline-tengine sh -c 'nginx -t && nginx -s reload' fi

如果编辑custom_confs目录下对应的 backend_x 文件
location /webalizer { alias /var/www/usage; autoindex on; } location /status { stub_status on; #allow 127.0.0.1; #deny all; } location /mrtg { proxy_set_header Host $host; proxy_set_header X-Forwarded-Scheme $scheme; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://192.168.0.1:80/mrtg/; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; proxy_http_version 1.1; }

@lendy98
Copy link

lendy98 commented Nov 23, 2023

不知道为什么,这个代码功能无效

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants