当用户的请求如下时,我想将用户重定向到 /app/acme
http://our-internal-app or
http://our-internal-app/
如果 squid 可以拦截这些请求,那么它的配置应该是什么?
答案1
我让它工作了
#!/usr/bin/python
import sys
import re
url_regex = re.compile(r'^http:\/\/our-internal-app(\/|\/index.html?)?$')
def rewrite_url(line):
""" If the input URL contains a port number, strip it out """
url_list = line.split(' ')
old_url = url_list[0]
new_url = '\n'
if url_regex.search(old_url):
new_url = 'http://our-internal-app/app/acme' + new_url
return new_url
while True:
line = sys.stdin.readline().strip()
new_url = rewrite_url(line)
sys.stdout.write(new_url)
sys.stdout.flush()
然后在 squid.conf 上,我添加了这个
url_rewrite_program /etc/squid/redir.py
url_rewrite_children 5
然后我向正在运行的 squid 发送了一个 HUP 信号来重新加载配置