简体   繁体   中英

Squid Proxy Authentication fails

I followed this tutorial to setup my proxy server. Installed Squid and apache2-utils

Created username and password using htpasswd

sudo htpasswd /etc/squid3/squid_passwd myusername

Appended the folowing lines to squid.conf

auth_param basic program /usr/lib/squid3/ncsa_auth /etc/squid3/squid_passwd
auth_param basic credentialsttl 2 hours
auth_param basic casesensitive off
acl ncsa_users proxy_auth REQUIRED
http_access allow ncsa_users

restarted squid server. And checked username and password in cmd. It says Ok

/usr/lib/squid3/ncsa_auth /et/squid3/squid_passwd
myusername password
OK

But i am not able to access from PHP

$proxy = "111.11.11.11:8220"; // my squid ip and port
$proxyauth =   base64_encode('username:pass');   // Tried without base64_encode also  
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD,  $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
echo $curl_scraped_page;
if(curl_error($ch))
{
    echo 'error:' . curl_error($ch);

}
curl_close($ch);

But i am getting X-Squid-Error: ERR_ACCESS_DENIED error

You were using the wrong authentication library to access the password file

auth_param basic program /usr/lib/squid3/ncsa_auth /etc/squid3/squid_passwd

should have been

auth_param basic program /usr/lib/squid3/basic_ncsa_auth /etc/squid3/squid_passwd

I had this problem when I was creating proxy servers with https://createproxy.com

After 2 complete rewrites and 200 tries by mistake I changed squid username to contain only characters (no mixed string with numbers). And it start working! Until today have no idea why you need to use only characters as squid username.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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