-1

I'd like to redirect users to /app/acme when their request is like this

http://our-internal-app or
http://our-internal-app/

If squid can intercept these requests, what would be the configuration for it?

devwannabe
  • 181
  • 3
  • 14
  • It would be the configuration you've tested and verified to work. What do you have so far? –  Aug 01 '16 at 20:48
  • Any uri request is sent to our nginx. It's nginx that decides what to do with the traffic. If it's /, it goes to our application-A. If it's /app/appB, it goes to appB. However, we create a new Squid that points to this existing nginx. I cannot change `location / { ... }` in nginx because it's being used. The new Squid is for our demo but I want to intercept / or /index.html so that it doesn't reach our nginx. This is the reason why I didn't want to put this text in my main post. There is no need to explain this. – devwannabe Aug 01 '16 at 20:54
  • so the new squid is a cloned image of our existing squid – devwannabe Aug 01 '16 at 20:54
  • Have you read through this? http://wiki.squid-cache.org/Features/Redirectors – Zoredache Aug 01 '16 at 22:15
  • No but what I've been reading about is url_rewrite_program. I'll check your link now. Thanks! – devwannabe Aug 01 '16 at 22:21
  • oh it's the same! I have a concern. Won't the script we specify in `url_rewrite_program` always gets called on every request? Won't that put more load into the system? – devwannabe Aug 01 '16 at 22:37

1 Answers1

1

I got it working

#!/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()

then on squid.conf, I added this

url_rewrite_program /etc/squid/redir.py
url_rewrite_children 5

Then I sent a HUP signal to our running squid to reload the config

devwannabe
  • 181
  • 3
  • 14