Linux menu

Thursday, September 18, 2014

How to configure Squid Proxy Server (CentOS, Fedora or RHEL)

Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It runs on most available operating systems, including Linux and Windows

To configure Squid, do the following:
1) Installing squid:
[root@server ~]# yum install squid -y
2) Now, open the squid's configuration file /etc/squid/squid.conf and addACLs there as per your requirement, you must define your ACLs in the beginning of the file (you will find a lot of predefined acls there, you can define yours just below them). Syntax of a ACL is:
acl <acl name> <acltype (like: source/destination)> 
Few sample acls are:
acl anyname src 192.168.0.0/255.255.255.0
acl somename dst 10.0.0.0/255.255.0.0
acl yahoo srcdomain .yahoo.com
acl google dstdomain .google.com 
The acltypes used in above statements are:
src => source
dst => destination
dstdomain => destination domain
srcdomain => source domain

3) Next, to allow or deny these ACLs, do the following entries but before the line saying http_access deny all:
http_access deny anyname 
http_access deny somename
http_access allow yahoo
http_access allow google

#the above lines should be declared before this line
http_access deny all
4) By default, squid runs on port 3128 but if you want to change it then search for following line and replace 3128 to your desired available port:
http_port 3128  #replace 3128 with your desired port no.
5) Now, save and exit the file and start the squid service:
[root@server ~]# service squid restart
[root@server ~]# chkconfig squid on
Squid server must be running now, in case of any errors please check/var/log/messages.

No comments: