squid is an efficient proxy server and Web caching server. It has a long history of development and complete functions. In addition to HTTP, the support for FTP and HTTPS is also quite good, and IPv6 is also supported in the 3.0 beta version. I have tried a good VPS intermittently several times, and the time span is very long, so it is necessary to make a summary memo of the previous ones. Based on personal abilities, errors and omissions are inevitable. Please correct me if possible! Some of the settings are sourced from the Internet, especially tiger.im, for the great assistance. I would like to express my gratitude here.
A server reverse proxy B (web server)
First, let’s take a look at how to use one server or VPS to reverse proxy another server or a domain name on another server. Let's assume that the server used for squid is A, and the real backend web server is B.
First, compile Squid on server A, log in to A with ssh as the root account, and run the following commands (this article is based on CentOS 5.* 32bit)
yum install squid
The compilation process is very fast. If httpd is installed, you can remove it.
yum remove httpd
Next is the most important part. Edit the squid.conf file (file location/etc/squid/). There are many configuration items in squid.conf. There are also many general setting tutorials on the Internet. In this article, we mainly record how to use it. Replace another server or domain name, so we only list the front-end and back-end addresses and domain names that need to be modified. You can also download the configuration file provided by the VPS tribe to modify it: Click to download squid.conf
cache_peer *.*.*.* parent 80 7 no-query originserver name=www1
cache_peer_domain www1 vpsok.net www.vpsok.net
Replace *.*.*.* above with your web server IP. If there are multiple domain names, you can add www2, www3... If you reverse all domain names on the web server, you can delete the cache_peer_domain line.
Upload after completion and reload Squid.
service squid reload
Set to start squid on boot
chkconfig –level 2345 squid on
chkconfig squid on
After doing this, you can resolve the domain name on server B and point it to the IP of server A, and server A will reverse the final address. This method is simple and easy to implement. For example, European servers are cheap, but domestic access speed is not good. You can give him a Squid front end from Hong Kong, Taiwan, Japan and South Korea. The speed improvement after caching is quite obvious; but the disadvantage is that directly using 80 If the port is reversed, it will be more troublesome to use this Squid server as a web server.
Squid front-end nginx back-end in LNMP environment
This method is operated on the same server, using squid as the front end and nginx back end on the web server that compiles the lnmp environment.
First, compile lnmp, the process is abbreviated (the basics of lnmp one-click package in this article)
After completion, install Squid
yum install squid
Delete the default squid configuration file
rm /etc/squid/squid.conf
Then pass in the squid.conf provided in the previous method (you can also edit it yourself)
In this method, we also need to modify the configuration file, because Squid uses port 80 as the front end, and nginx also uses port 80. , it is definitely not possible to use port 80. In this article, we modify nginx to use port 8888. First, let’s modify the squid.conf file.
cache_peer 127.0.0.1 parent 8888 7 no-query originserver name=www1
cache_peer_domain www1 vpsok.net www.vpsok.net
The 127.0.0.1 above represents the reverse proxy local backend. Port 8888 can be modified by yourself as long as it does not conflict with other ports in the system.
If you need multiple proxies, you can continue to add them.
Next, we also need to modify the nginx configuration information.
vi /usr/local/nginx/conf/nginx.conf
Modify port 80 to 8888
server
{
listen 8888;
If you want to add a domain name to automatically use port 8888 in the future, you can also modify the vhost.sh file.
server
{
listen 8888;
server_name
$domain
$moredomaname
;
index index.html index.htm index.php
default
.html
default
.htm
default
.php;
After everything is completed, restart lnmp and squid.
/root/lnmp restart
service squid restart
Finally set Squid to start at boot.
chkconfig –level 2345 squid on
chkconfig squid on
In this way, our site on this server is the squid front end and nginx back end.