Nginx is a performance-oriented design HTTP server, compared to Apache, lighttpd has possession of less memory, high stability advantages. With the old version (< = 2.2) of different Apache, nginx is not a thread-per-client design model, but full use of asynchronous logic, reducing the scheduling overhead context, the concurrent service ability. Overall modular design, the module has a wealth of third-party libraries and library modules, flexible configuration. In the Linux operating system, nginx use epoll event model, thanks to this, nginx under the Linux operating system, very high efficiency. Meanwhile Nginx uses an efficient event model similar to epoll kqueue on OpenBSD or FreeBSD operating system. nginx is also a high-performance HTTP server and reverse proxy, also a IMAP / POP3 / SMTP proxy server. Nginx already because of its stability, rich feature set, simple configuration, and low resource consumption and the famous.
Today my topic it is mainly Nginx load balancing test, the steps do record it as a learning notes, can also give you the next reference.
1. Experimental environment
System version: CentOS release 5.9 (Final) x86 32 Wei
nginx version: 1.2.8 nginx load balancing location: 125.208.14.177 80 port web1 125.208.12.56:80 port web2 218.78.186.162:8090 port web3 125.208.14.177:8080 port
Here it, I use on web_1 and web_2 system comes with apache, required to change the listening port ok, of course, you can also install nginx, that you can figure it out, I 125.208.14.177 on installation nginx, used as a load balancer and web servers, load balancing using port 80, and the web service uses port 8080.
2: Profiles
[root @ host-192-168-2-177 conf] # more nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
upstream site {
server 125.208.12.56:80;
server 218.78.186.162:8090;
server 125.208.14.177:8080;
} include mime.types;
default_type application / octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
proxy_pass http: // site; root / var / www / html;
index index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .php $ {
root / var / www / html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 8080;
server_name localhost2;
location / {
root / var / www / html2;
index index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .php $ {
root / var / www / html2;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
include fastcgi_params;
}
}
}
3: Test
[root @ host-192-168-2-177 conf] # curl 125.208.14.177
404 Not Found
404 Not Found
----------------------------------------------- --------------------------------- nginx
[root @ host-192-168-2-177 conf] # curl 125.208.14.177 1234 [root @ host-192-168-2-177 conf] # curl 125.208.14.177 this dir is / var / www / html2
--- successful visit polling |