Use CentOS7 to configure the Squid Proxy

Source: Internet
Author: User
In fact, I used a squid, but because it was too lazy, I searched for a tutorial on the internet, used the default port, and did not add user authentication. One day, unfortunately, it was scanned by crawlers and sent half a month of spam .. It was not until one day that I logged on to my mailbox and saw a large warning email that I realized that the problem was serious. After a stunned stay, hurry and re-configure it -.-

In fact, I used a squid, but because it was too lazy, I searched for a tutorial on the internet, used the default port, and did not add user authentication. One day, unfortunately, it was scanned by crawlers and sent half a month of spam .. It was not until one day that I logged on to my mailbox and saw a large warning email that I realized that the problem was serious. After a stunned stay, hurry and re-configure it -.-

I used squid to configure a common proxy with user authentication.

Install

The installation process is very simple. You only need to install squid, oneCommandDone. Squid3.3 is installed here.

yum install squidrpm -qa | grep squidsquid-3.3.8-12.el7_0.x86_64
Configuration

Modify the squid configuration file/etc/squid. conf.

Configure Ports, caches, logs, and access rules.

Http_port 3712
cache_mem 64 MBmaximum_object_size 4 MBcache_dir ufs /var/spool/squid 100 16 256access_log /var/log/squid/access.loghttp_access allow allvisible_hostname squid.chao
Initialization

You need to reinitialize the cache directory before the first startup or after modifying the cache path.

squid -z
Start
systemctl start squid
Use

Modify the proxy configuration in the browser.

In windows:

Internet Options-> connection-> LAN connection-> Proxy Server

In macOSX:

Safari> preference Settings> proxy> Web Proxy

Enter your proxy address and port to work properly.

Test

I can see a very simple method from the Internet, which can be used to quickly test whether your proxy works normally. First open Baidu, and then search for the ip address. If the ip address of the machine on which you acted, congratulations! A large wave of spam is coming soon.

Add User Authentication

To prevent our Proxy from being crawled and used for illegal purposes, it is necessary to add user authentication for our squid. As a matter of fact, I Just configured a proxy and it didn't take long before it was scanned.

I can see from my access. log. However, at this time, I have not added any authentication mechanism. Fortunately, I did not use port recognition. Otherwise, my mailbox will receive a large warning email ..

1439106533.703      0 89.102.9.196 TCP_DENIED/403 3739 GET http://www2.praguerentacar.com/proxy/detectproxy.php - HIER_NONE/- text/html1439106539.302      0 89.102.9.196 TCP_DENIED/403 3724 GET http://www2.intimnosti.cz/proxy/detectproxy.php - HIER_NONE/- text/html1439106544.881      0 89.102.9.196 TCP_DENIED/403 3706 GET http://93.185.96.50/proxy/detectproxy.php - HIER_NONE/- text/html1439106550.453      0 89.102.9.196 TCP_DENIED/403 3712 GET http://www2.nuabi.com/proxy/detectproxy.php - HIER_NONE/- text/html

 

We use the ncsa authentication module to add authentication for our squid. Why I chose ncsa, because I found it from the Internet and used it mostly ..

First, we need to configure the account information of our access users. The last parameter is the user name, which can be replaced with any name you like ~

htpasswd -c /etc/squid/passwd chao

If you cannot find htpasswd, install Apache first. Yum install httpd. Then you can use htpasswd.

With the account file, we reconfigure our squid. In squid. conf

http_access allow all

Change

auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwdauth_param basic children 5auth_param basic realm chao's squid serverauth_param basic credentialsttl 2 hoursacl myacl proxy_auth REQUIREDhttp_access allow myaclhttp_access deny all

Restart squid.

systemctl restart squid

Now, when you access the page using a proxy, a prompt box will pop up asking you to enter the user name and password. Then you can continue the access.

 

 

Configuration instructions

Some people may not catch up with the principle and configuration at first, but they just want the agent to run it first. At least I am myself .. So I put this piece at the end.

Now, let's take a look at the specific configuration content above. Of course, refer to the official website for more detailed and accurate information.

Http_port 3712 specifies the proxy port.

Cache_mem cache size in 64 MB memory

Cache_dir ufs/var/spool/squid 100 16 256 cache folder, Which is cached only in memory by default. The cache size is 100 MB, 16 sub-directories at the first layer, and 256 at the second layer.

Maximum_object_size: the maximum size of the cached file in 4 MB. This is used with cache_dir and only applies to files cached on the disk.

Access_log/var/log/squid/access. log access log

Auth_param basic program/usr/lib64/squid/basic_ncsa_auth/etc/squid/passwd specify the authentication program and account file

Auth_param basic children 5: Number of concurrent authenticate programs

Description text in the prompt box popped up when the auth_param basic realm chao's squid server client uses the proxy and enters the password.

Auth_param basic credentialsttl 2 hours certification duration

Acl myacl proxy_auth REQUIRED authenticate myacl using external programs

Http_access allow myacl allows access by members in myacl

Http_access deny all other access

Visible_hostname squid. chao proxy machine name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.