杀死白雪公主 2008-4-14 12:31
[百科]Nginx 简单的负载均衡配置示例
用户访问[url]http://www.s135.[url=http://whatis.ctocio.com.cn/searchwhatis/307/5947307.shtml]com[/url][/url],将其负载均衡到192.168.1.2:[url=http://whatis.ctocio.com.cn/searchwhatis/293/5949293.shtml]80[/url]、192.168.1.3:80、192.168.1.4:80、192.168.1.5:80四台[url=http://server.ctocio.com.cn/]服务器[/url]。
用户访问[url]http://blog.s135.com[/url],将其负载均衡到192.168.1.7服务器的8080、8081、8082端口。
以下为配置文件nginx.conf:
引用
[[url=http://whatis.ctocio.com.cn/searchwhatis/456/6028456.shtml]table[/url]=95%][tr][td]user www www;
worker_processes 10;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
#最大文件描述符
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include conf/mime.types;
default_type [url=http://whatis.ctocio.com.cn/searchwhatis/315/6025315.shtml]application[/url]/octet-stream;
keepalive_timeout 120;
tcp_nodelay on;
upstream [url]www.s135.com[/url] {
[url=http://whatis.ctocio.com.cn/searchwhatis/497/5948997.shtml]server[/url] 192.168.1.2:80;
server 192.168.1.3:80;
server 192.168.1.4:80;
server 192.168.1.5:80;
}
upstream blog.s135.com {
server 192.168.1.7:8080;
server 192.168.1.7:8081;
server 192.168.1.7:8082;
}
server
{
listen 80;
server_name [url]www.s135.com[/url];
location / {
proxy_pass [url]http://www.s135.com[/url];
proxy_set_header Host $[url=http://whatis.ctocio.com.cn/searchwhatis/128/5948128.shtml]host[/url];
proxy_set_header X-Real-[url=http://whatis.ctocio.com.cn/searchwhatis/191/6025691.shtml]IP[/url] $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
log_format www_s135_com '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /data1/logs/www.log www_s135_com;
}
server
{
listen 80;
server_name blog.s135.com;
location / {
proxy_pass [url]http://blog.s135.com[/url];
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
log_format blog_s135_com '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /data1/logs/blog.log blog_s135_com;
}
}[/td][/tr][/table] 附:Nginx 的安装方法可参照《Nginx 0.5.31 + [url=http://whatis.ctocio.com.cn/searchwhatis/77/6026077.shtml]PHP[/url] 5.2.4([url=http://whatis.ctocio.com.cn/searchwhatis/352/5947852.shtml]FastCGI[/url])搭建可承受3万以上并发连接数,胜过[url=http://whatis.ctocio.com.cn/searchwhatis/299/6025299.shtml]Apache[/url] 10倍的Web服务器》文章的以下段落(仅做负载均衡,无需支持PHP的安装方法):
二、安装PHP 5.2.4(FastCGI模式)
4、创建www用户和组,以及其使用的目录:
三、安装Nginx 0.5.31
1、安装Nginx所需的pcre库:
2、安装Nginx
3、创建Nginx日志目录
5、启动Nginx
didazhangqi1bc6 2008-7-26 21:27
你好,我看你了发了很多负载均衡这方面的资料,想向你请教一下.不知道可否告诉一下你的联系方式?谢了!
moverinfo6d0391 2008-8-7 10:38
学习