Build Squid Reverse Proxy Server

Source: Internet
Author: User

Okay, update an article. I haven't written any technical blog for a while. Today, let's talk about the squid reverse proxy service. Of course, this is completed in Linux. It seems impossible to say that you are not biased. Like Linux. However, I never deny that Windows Server has poor functions and performance than Linux. It's just a personal hobby. The following describes how to set up squid reverse proxy for multiple domain names and multiple web sites.

Environment (this is important)

Two CentOS6.3 and one RHEL6.2

Nic information and DNS record information are too many, so it seems a little annoying. You just need to check the information clearly. It is purely personal preferences and habits.

DNS Server IP: 192.168.2.10 (VMnet2)

Squid Server IP Address: (for dual NICs, do proxies usually act as Internet visitors, so you don't have to worry about it yourself.) In the VMnet8 'nat 'mode, do not enable DHCP allocation for VMware, after you view the information, update it to a static IP address.) 192.168.8.113/24, internal and external (VMnet2) 192.168.2.20/24

For the internal WEB Server IP Address: 192.168.2.30-33/24 (VMnet2), refer to the following DNS configuration for the name of the Virtual Host Configuration:

[Root @ localhost named] # more than 192.zone $ TTL 1D @ in soa @ rname. invalid. (0; serial 1D; refresh 1 H; retry 1 W; expire 3 H); minimum NS @ MX 5 @ A 192.168.2.10 PTR ns.zwz.com. 20 PTR mail.zwz.com. PTR pop3.zwz.com. PTR smtp.zwz.com. PTR www.zwz.com. PTR squid.zwz.com. PTR www.wl.com. 30 PTR ftp.zwz.com. 30 PTR www1.zwz.com. 31 PTR www2.zwz.com. 32 PTR www3.wl.com. 33 PTR www4.wl.com. [root @ localhost named] #

The DNS records corresponding to the red text above all point to the corresponding site of the internal WEB server. The blue text points to the Squid server, that is, the domain name for Internet access. These are done using the CNAME method. Because there are two domain names and they are all records of the same reverse region, only the reverse resolution configuration file is generated here. The configuration required for forward Parsing is correct.

Note: In fact, www.zwz.com and www.wl.com are the applied public IP addresses.

Start with the WEB server configuration. The following is the configuration of the Apache Virtual Host site:

NameVirtualHost 192.168.2.30: 80 NameVirtualHost 192.168.2.31: 80 NameVirtualHost 192.168.2.32: 80 NameVirtualHost 192.168.2.33: 80 <VirtualHost 192.168.2.30: 80> ServerAdmin admin@zwz.com DocumentRoot/var/www/html/web1 ServerName internal DirectoryIndex index.html. var ErrorLog logs/dummy-host.example.com-error_log CustomLog logs/dummy-host.example.com-access_log common </VirtualHost> <VirtualHost 192.168.2.31: 80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot/var/www/html/web2 ServerName www2.zwz.com DirectoryIndex index.html ErrorLog logs/dummy-host.example.com-error_log CustomLog logs/dummy-host.example.com-access_log common </VirtualHost> <VirtualHost 192.168.2.32: 80> ServerAdmin admin@wl.com DocumentRoot/var/www/html/wl1 ServerName www3.wl.com directoryindex index.html ErrorLog logs/dummy-host.example.com-error_log CustomLog logs/dummy-host.example.com-access_log common </VirtualHost> <VirtualHost 192.168.2.33: 80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot/var/www/html/wl2 ServerName www4.wl.com directoryindex index.html ErrorLog logs/dummy-host.example.com-error_log CustomLog logs/dummy-host.example.com-access_log common </VirtualHost> [root @ localhost html] #

The configuration of Apache Virtual Hosts is not mentioned here.

Finally, configure the squid reverse proxy server. In fact, squid's acl is still very powerful, and I have never studied it in depth. However, it seems like Microsoft's ISA. In combination with iptables in Linux, you can also implement a relatively simple lan software firewall.

1. Install squid software-local yum. Yum install-y squid.

2. There are not many configuration files in the directory/etc/squid. In addition, we only need to modify the squid. conf configuration file in this directory. Again, this document only contains some parameters of the squid software, many of which are not shown in this document.

Acl all src 0.0.0.0/0.0.0http _ access allow all # Note: Note that this sentence should be written before the default deny all. The acl is gone. If it is not parsed, it will be read in sequence. Cache_log/usr/local/squid/var/logs/cache. logaccess_log/usr/local/squid/var/logs/access. log squidcache_dir ufs/usr/local/squid/var/cache/1000 16 256coredump_dir/var/spool/squid # Needless to say, the specific path strength of related directories such as log/cache. Http_port 80 accel vhost vport # configure squid as the acceleration mode and use the virtual host configuration. Cache_mem 64 MB # squid is used to cache the amount of memory. Because I used VMware to complete the operation and the system only gave 265 MB in total, I only gave 64 MB. Cache_swap_low 90cache_swap_high effecsquid # specify the cache's valid user group cache_effective_group squid # specify the effective user group visible_hostname ## set the squid host name. If this parameter is not specified, squid cannot be. Cache_peer 192.168.2.30 parent 80 0 no-query originserver round-robin name = www1cache_peer_domain www1 www. zwz. comcache_peer 192.168.2.31 parent 80 0 no-query originserver round-robin name = www2cache_peer_domain www2 www.zwz.com # the above four sentences mean to send requests to the site www.zwz.com through RR round robin, if the data requested by the user is local # There is data on the Squid server, it will be returned directly. Otherwise, the data will be requested from the web source site and then returned to the user. Here we can see Xiami (Cdn, hey !) Cache_peer 192.168.2.32 parent 80 0 no-query originserver round-robin name = www3cache_peer_domain www3 www. wl. comcache_peer 192.168.2.33 parent 80 0 no-query originserver round-robin name = www4cache_peer_domain www4 www.wl.com # the above four sentences ~

The above configuration can clearly identify the conflicting acl and then directly add it to the end of this document. After the configuration file is installed, there are several configuration documents in the/etc/squid/directory, or several corresponding archives (with. default)

Okay. So far, start the relevant services on the relevant server for testing. I used the physical machine to modify the hosts method for testing. Add the NAT Nic IP address of the squid server corresponding to the host's hosts record to direct to www.zwz.com and www.wl.com. The hosts file is generally in the C: \ Windows \ System32 \ Drivers \ etc directory.

Note: Do not use the chrom browser for testing. It seems that the browser has a kind of proxy request, which is actually the cache within the scope of the software. It seems that it is still stubborn and can be tested using IE or Firefox, (I use the private mode to browse drops ). Okay, let's take a look:

First visit www.zwz.com

Refresh access to www.zwz.com

First visit www.wl.com

Refresh access to www.wl.com

There are still some ideas after the configuration is completed. Currently, it seems that this is not very popular. However, they should also be used by people. Which of the following is Nginx ~

Fixed Link: http://www.kutea.net/639.html

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.