在加速器模式下使用自定义身份验证帮助程序配置squid(反向代理)

时间:2010-11-30 11:36:03

标签: authentication reverse-proxy squid

我需要将Squid配置为反向代理,并为每个传入请求配置自定义身份验证帮助程序。假设Squid的每个请求都使用基本身份验证。任何未通过身份验证的连接都应终止。我是鱿鱼的新手。以下是我使用的配置脚本。此示例将访问“mindofaprogrammer.blog.com”,

acl all src all
acl manager proto cache_object

http_port 80 accel defaultsite=mindofaprogrammer.blog.com
cache_peer mindofaprogrammer.blog.com parent 80 0 no-query originserver name=myAccel

acl myblog dstdomain mindofaprogrammer.blog.com
http_access allow myblog
cache_peer_access myAccel allow myblog
cache_peer_access myAccel deny all


auth_param basic program C:/wamp/bin/php/php5.3.0/php.exe "c:/squid/libexec/authhelper.php"
auth_param basic children 2
auth_param basic realm eReader
auth_param basic credentialsttl 5 hours

acl AuthUsers proxy_auth REQUIRED
http_access allow AuthUsers

access_log c:/squid/var/logs/access.log squid
coredump_dir c:/squid/var/cache

我在PHP脚本中编写了自定义身份验证帮助程序。列出的内容如下,

<?php
$f = fopen("php://stdin", "r");
while ($line = fgets($f)) {
        $line = trim($line);
        $fields = explode(' ', $line);
        $username = rawurldecode($fields[0]); //1738
        $password = rawurldecode($fields[1]); //1738
        if ($username == 'hello' 
            and $password == 'world') {
                fwrite(STDOUT, "OK\n");
        } else if ($username == 'fo'
            and $password == 'bar') {
                fwrite(STDOUT, "OK\n");
        } else {
                // failed miserably
                fwrite(STDOUT, "ERR\n");
        }
}
?>

我面临的问题是,即使配置完成后,只有反向代理设置正在运行而不是身份验证。我在这里做错了吗?

1 个答案:

答案 0 :(得分:0)

我认为您首先需要在最底部添加http_access deny all

然后你应该将两个http_access'组合成一行(作为“ AND ”运算符),如下所示:

http_access allow AuthUsers myblog

请记住,Squid始终使用匹配的第一行,并且停止进一步处理,您的行http_access allow myblog只接受所有请求并停止向下移动认证部分。