简体   繁体   English

python cgi脚本始终被apache2 2.4.6禁止使用403

[英]python cgi script always got 403 forbidden with apache2 2.4.6

work environment: Ubuntu 13.10 saucy, apache2 2.4.6 工作环境:Ubuntu 13.10 saucy,apache2 2.4.6

I have a python script in /usr/lib/cgi-bin and I use it as a proxy for convert internal url to external. 我在/ usr / lib / cgi-bin中有一个python脚本,我将其用作将内部url转换为外部url的代理。 it works great with apache 2.2 but always got 403 forbidden error. 它与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()

any tips for apache new version I should follow? 我应该遵循的有关Apache新版本的任何提示吗?

apach2 2.4.6 don't put cgid.conf and cgid.load in /etc/apache2/mods-enabled as default. apach2 2.4.6不要将cgid.conf和cgid.load放在默认情况下的/ etc / apache2 / mods-enabled中。 after make soft link from mods-available to mods-enabled, the issue be fixed. 使从mods可用的软链接到启用mods的链接之后,此问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM