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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With