工作环境:Ubuntu 13.10 saucy,apache2 2.4.6
我在 /usr/lib/cgi-bin 中有一个 python 脚本,我用它作为将内部 url 转换为外部的代理。它适用于 apache 2.2,但总是出现 403 禁止错误。
/etc/apache2/site-enabled/mirror.conf
ScriptAlias /mirror /usr/lib/cgi-bin/mirror.py
/usr/lib/cgi-bin/mirror.py
#!/usr/bin/python
import os
import sys
import pycurl
username = "username"
password = "password"
base = "https://mirror.xxxxxxxx.com/xxxxxxxx"
if os.environ.has_key(‘PATH_INFO’):
path = os.environ[‘PATH_INFO’]
else:
path = ‘/’
dst = base + path
def write(data):
sys.stdout.write(data)
def header(data):
for line in data.splitlines():
if line.startswith('HTTP/'):
ret = line.split()[1]
sys.stdout.write('Status: ' + ret + '\r\n')
elif line.startswith('Location:'):
line = line.replace('https://mirror.xxxxxxxx.com/xxxxxxxx', 'http://mirror.internal/mirror')
sys.stdout.write(line + '\r\n')
else:
sys.stdout.write(line + '\r\n')
curl = pycurl.Curl()
curl.setopt(curl.URL, dst)
curl.setopt(curl.HEADERFUNCTION, header)
curl.setopt(curl.USERPWD, '%s:%s' % (username, password))
curl.setopt(curl.WRITEFUNCTION, write)
curl.perform()
curl.close()
我应该遵循的有关 apache 新版本的任何提示?