Installation & Configuration for Proxy service Squid3

This aritcle describes squid installation & configuration on Cent OS 7.

👽 Server Environment

OS: CentOS 7
Squid: Version 3.3.8

🎂 Installation

$ sudo yum -y install vim-enhanced squid

🐡 Squid Configuration

You should change Squid configuration vim /etc/squid/squid.conf.

At frist, comment out default setting:

#http_access deny all
#http_port 3128

Add customized configuration in last line:

# Host Name

# Port
http_port 8080

# Basic auth
# Ref
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/.passwd
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
auth_param basic casesensitive off

# Define ACL
acl ncsa_users proxy_auth REQUIRED

# Set permission to ACL
http_access allow ncsa_users

# Anonymization
forwarded_for off
request_header_access X-Forwarded-For deny all
request_header_access Via deny all
request_header_access Cache-Control deny all

# No Caching
no_cache deny all

🐹 Basic Authorization

# Install apache tools to use htpasswd command
$ yum install httpd-tools

# Set USER/PASSWORD to basic auth
$ useradd <USER>
$ sudo htpasswd -c /etc/squid/.passwd <USER>
> New password: <PASS>
> Re-type new password: <PASS>

😀 Start Squid

# clear cache
$ squid -z

# Start Squid
$ service squid start

🐞 firewall-cmd Configuration

# Allow your IP address
$ firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="x.x.x.x" port protocol="tcp" port="8080" accept"
# Allow all IP address
# $ firewall-cmd --permanent --zone=public --add-port=8080/tcp
$ firewall-cmd --reload

🍄 Confirmation

🐰 Sample Code

You can confirm proxy configuration by Ruby Code like the following:

Install Ruby Gems

$ gem install faraday
$ gem install faraday_middleware

Please run following ruby code:

require 'faraday'
require 'faraday_middleware'

connection = {
uri: 'http://xx.xx.xx.xx:8080',
user: 'USER',
password: 'PASS'
}) do |conn|
conn.use FaradayMiddleware::FollowRedirects
conn.adapter :net_http

response = connection.get ''
response.status #=> 200 OK

😼 Special Thanks

🖥 Recommended VPS Service

VULTR provides high performance cloud compute environment for you. Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour). In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!