Currently, popular Server Load balancer front-end servers include Apache (with mod_proxy), nginx, Lighttpd, squid, perlbal, and pound. If your domain name service provider provides DNS-level Server Load balancer, or (that is, a domain name randomly points to multiple IP addresses, and the customization is not high ).
In the past, I used pound as the front-end. It focuses on Server Load balancer, supports HTTPS protocol, and the configuration is still simple. However, it is gradually found that the function is not powerful enough. Instead, I want to study other functions that can be used for Server Load balancer, it can also be a high-performance tool for Web servers. Perlbal is the first masterpiece of danga. The memcached (distributed memory cache system) developed by danga is very easy to use and perlbal is not bad. Although it is based on Perl, the speed is slightly inferior to that of pure C development, but danga has extraordinary strength. However, the company's machines are perl5.8.5, and perlbal must be perl5.8.8 or above. The upgrade may have compatibility problems, so you can leave it alone.
Nginx ("engine X") is a high-performance HTTP and reverse proxy server and an IMAP/POP3/SMTP proxy server. Nginx was developed by the rambler.ru site with the highest access volume in Russia as Igor Sysoev. It has been running on this site for more than two and a half years. Igor publishes source code in the form of a class BSD license. Despite being a beta version, nginx is well known for its stability, rich feature sets, sample configuration files, and low system resource consumption.
Chinese wiki address: http://wiki.codemongers.com/NginxChs
Module dependency:
1 gzip support, need zlib http://www.zlib.net/download the latest version can be
2 rewrite module requires PCRE Library http://www.pcre.org/download the latest version
3 SSL functions need OpenSSL library http://www.openssl.org/=> http://www.openssl.org/source/ lastest version can be
Installation Process:
# Download the above source to the/usr/local/src/nginx/directory and decompress the package. The following figure shows the situation in this directory:
[Root @ S16 nginx] # ls
Nginx-0.6.32 nginx-0.6.32.tar.gz openssl-0.9.8i openssl-0.9.8i.tar.gz pcre-7.8 pcre-7.8.tar.gz zlib-1.2.3
CD nginx-0.6.32
./Configure -- With-PCRE = ../pcre-7.8 -- With-zlib = ../zlib-1.2.3 -- With-OpenSSL = ../openssl-0.9.8i
Make
Make install
# OK, Installation Complete
# Modify configuration:
CD/usr/local/nginx
Vi conf/nginx. conf
# For example, remove the comment on the server configuration of port 8000 in the example.
Sbin/nginx-t-c CONF/nginx. conf (test whether the configuration file is correct)
[Root @ S16 nginx] # sbin/nginx-t-c CONF/nginx. conf
15:26:55 [info] 15879 #0: the configuration file CONF/nginx. conf syntax is OK
15:26:55 [info] 15879 #0: the configuration file CONF/nginx. conf was tested successfully
Sbin/nginx (start)
PS aux | grep nginx | grep-V grep (check whether it is started normally)
# If it is not started properly, check the errorlog. default location:/usr/local/nginx/logs/error. Log
# Through Apache Connector testing, nginx has no better performance than Apache (with mod_perl) in serving static files. Basically, it uses 65k as the demarcation point, the nginx performance is good for small files (up to about 3 times the speed), and Apache performance is good for large files (but the difference is limited). In terms of speed, nginx is not better than Apache, but nginx is small and consumes less resources. If you need to serve many static small files, it is indeed a good choice.
Here we recommend an architecture:
1 front-end nginx, and serve static files, slices, JS, CSS, etc. nginx supports gzip compression.
2. the backend dynamic program uses FastCGI (spawn_fcgi of Lighttpd) and supports PHP, Perl, and other scripting languages.
The following describes common nginx configurations:
- Use nginx to serve static files directly:
# CSS | JS | ICO | GIF | JPG | JPEG | PNG | TXT | HTML | HTM | XML | SWF | these are static files, but they must be distinguished, JS and CSS may change frequently. The expiration time should be smaller, images and HTML will remain unchanged, and the expiration time can be longer <br/> location ~ * ^. + /. (ICO | GIF | JPG | JPEG | PNG | HTML | htm) $ {<br/> root/var/www/Poseidon/root/static; <br/> access_log off; <br/> expires 30d; <br/>}< br/> location ~ * ^. + /. (CSS | JS | TXT | XML | SWF | WAV) $ {<br/> root/var/www/Poseidon/root/static; <br/> access_log off; <br/> expires 24 h; <br/>}< br/> # Note: location does not include? So the above regular expression can match http: // 192.168.1.16/image/sxxx.jpg? A = xxx
Open gzip and compress the data
Gzip on; <br/> gzip_comp_level 7; <br/> gzip_min_length 1100; # minimum length to be compressed <br/> gzip_buffers 4 8 K; <br/> gzip_types text/plain application/JavaScript text/CSS text/XML application/X-httpd-PHP; # specify the file type to be compressed <br/> output_buffers 1 32 K; <br/> postpone_output 1460;