Article Title: Use Squid Proxy Server in LINUX. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Use Squid Proxy Server
Squid is a proxy server that caches HTTP, FTP, and Gopher protocols. Squid can use the Access Control List (ACL) to allow or deny Access. Squid has powerful configuration capabilities and robustness, and users will find that the software is very easy to learn. Better, you can configure Squid as a transparent proxy, as if the user does not know Squid at all.
1. obtain and install Squid
Users can get the latest version from FTP site: ftp://squid.nlanr.net/pub. The latest version is 2.3. Now, we assume that your proxy service has two network interfaces, one connected to the external world, and the other connected to the internal network, and you have disabled the IP forwarding function.
Icon Note: You can also create Squid on the server with only one network interface, but we do not recommend this. This configuration doubles the traffic on the local network and may cause congestion. At present, Nic and Hub prices are already very low, even for small networks, this investment is also worthwhile.
If you plan to use Squid to maintain the cache, consider hard drive and memory restrictions. The essence of Web Cache is that thousands of small files must be delivered to the customer simultaneously and effectively. The Squid authors suggest that at least 300 MHz Pentium ii cpu, 512 mb ram, and five ultra-wide SCSI hard disks, each with a capacity of 9 GB. I have heard that an Internet vendor only uses several 486/66 processors and IDE drives. I think most people are suitable for the two limits. We recommend that you use at least 100 MHz Pentium CPU, 64 mb ram, and 6 gb scsi hard drive. In fact, a slightly lower configuration does not matter much.
After obtaining the tar.gz file, use the following command to unbind it:
Tar zxvf squid-2.3.STABLE4-src.tar.gz
Run./configure in the directory where Squid is located to check system settings and create a configuration file. Then, enter make to compile Squid. If no error occurs, enter make install, which will be installed under/usr/local by default.
2 Use Squid
To create a switch directory, enter the following command:
/Usr/local/squid/bin/squid? Z
Before running this command for the first time, you must modify the/usr/local/squid. conf configuration file. By default, the Squid Access Control List rejects all requests. Edit the/usr/local/squid. conf file and add the following lines:
Acl local_net src 192.168.1.1/255.255.255.0
Here, 192.168.1.1 is an IP address in the local network, and 255.255.255.0 is the network mask of the internal network. You also need to add:
Http_access allow local_net
Place this line in front of http_access deny all. This defines IP address groups that allow the use of cache.
Enter squid & start Squid. You can verify the running of Squid in several ways:
L Squid should appear in the output list of ps-x.
L running client www.yahoo.com should print Web page text on the terminal.
L cache. log and store. log in/var/log/squid indicate that Squid is working.
L running squid-k check & echo "squid is running" will tell the user whether Squid is running.
Now perform a real test: In Netscap Navigator, you can select Edit-> Preference, and then select Proxies from the Advanced class for proxy settings. Select Manual Proxy Configuration and click View to specify the IP address of the Squid server as the HTTP, FTP, and Gopher Proxy servers. The default proxy port is 3128. Unless the default proxy port is modified in the squid. conf file, enter 3128 in the port box.
Now you should be able to browse any Web site. Check the log file/var/log/squid/access. log On the proxy server, and confirm that the browsed Web site is saved in the log file, so that the Squid is working again.
3. Configure Squid to meet your needs.
Now Squid can be run. You can customize it to meet your needs. So far, Squid does not limit user access to any site. You can define rules in the squid. conf file, set the access control list (ACL), and then allow or deny visitors based on these lists.
Add the following configuration line, which defines an ACL rule called BadWords. It matches any URL containing foo or bar:
Acl BadWords url_regex foo bar
This rule acts on the http://foo.deepwell.com/pictures and http://www.thekendycompound.com/ourbar.jpg, because these two URLs contain the two words defined by BadWords.
Add the following lines to the squid. conf file to prevent users from accessing any URLs that match the above rules:
Http_access deny BadWords
Icon Note: almost every administrator may encounter some situations when using word-based ACL. In such cases, words cannot be simply used. For example, if you want to prohibit users from accessing websites that contain "sex", they are also prohibited from accessing sites such as www.buildersexchange.com. Because "buildersexchange" is just defined by "sex.
Because all aspects of the Squid function are controlled by the squid. conf file, you can edit the file and adjust the Squid to meet your needs.
For example, add the following configuration line:
Cach_mem 16 MB
It will allow Squid to use 16 MB memory to save Web pages. After continuous attempts, you can find the appropriate quantity.
Icon Note: cache_mem is not the total memory consumed by Squid. It is only the maximum memory used by Squid to save Web page images. Squid's document says that Squid may consume three times the amount of memory.
Use the following configuration lines:
Emulate_httpd_log on
The format of log files in/var/log/squid is similar to that of log files on the Web server. In this way, you can use Web statistical programs, such as Analog or Webtrends, to analyze logs and learn about your usage.
Some FTP servers need to enter the email address as the password for anonymous login. By setting ftp_user as a valid email address, the server at the other end of the FTP session can receive the expected data, for example:
Squid@minigui.org ftp_user
You may want to use the address of the proxy firewall administrator, but this may cause problems when the external FTP administrator contacts you.
If the URL page is not found, it can be inferred that the page will not appear recently. By setting negative_ttl to the expected number of minutes, you can control Squid to remember the time not found on a page, for example:
Negative_ttl 2 minutes
The default value is 5 minutes, but if you do not want to disable it, I suggest reducing it to two minutes or one minute, because the user wants the proxy to be as transparent as possible. If the user is looking for a page that is known to exist, the agent should not find the report if the page can actually be obtained.
Cache_mgr proxy@minigui.org
Set cache_mgr to your own email address, so that Squid can send you an email when detecting cache problems.
Cache_inclutive_user nobody
Cache_inclutive_group nobody
These two lines are very important. If you start Squid as root, the two lines change the UID of Squid to "nobody ". This will avoid modifying or deleting bugs in the program that should not be modified or deleted.
Finally, tools like Squid should be completely transparent to users. In this way, users do not have to manage files in complex relationships and can view the Web, just as they do without a Web proxy server. The way to achieve this is not discussed in this book, and users can refer to Squid Q & A on the http://squid.nlanr.net/Squid/FAQ/FAQ.html, section 17th describes in detail how to set Squid as transparent proxy.
At the same time, if you need to manage a large "Blacklist" site in the squid. conf file, you can consider using a Redirection Program. A large list of ACL rules may reduce the speed of Squid proxy servers with heavy loads. With the Redirection Program, you can provide the efficiency of allowing or disabling URL access based on filtering rules. Users can get detailed information on squsert (http://www.senet.com.au/squirm), which is a fully functional Squid redirection.
The Squid release contains a cachemrg. cgi file. This file is a CGI program that can be used to view the agent statistics, or to close or restart Squid. The program can describe the execution of the agent with clear details. It also helps you adjust the Web cache.
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