首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Nginx 简略的负载均衡配置示例[转]

2012-12-18 
Nginx 简单的负载均衡配置示例[转]2007-10-29 20:50 | by 张宴 ]  www.s135.com 和 blog.s135.com 域名均

Nginx 简单的负载均衡配置示例[转]
2007-10-29 20:50 | by 张宴 ]

  www.s135.com 和 blog.s135.com 域名均指向 Nginx 所在的服务器IP。

  用户访问http://www.s135.com,将其负载均衡到192.168.1.2:80、192.168.1.3:80、192.168.1.4:80、192.168.1.5:80四台服务器。

  用户访问http://blog.s135.com,将其负载均衡到192.168.1.7服务器的8080、8081、8082端口。

  以下为配置文件nginx.conf:

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? '"$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 ? ? ? ?http://blog.s135.com;
? ? ? ? ? ? ? ? ? ? ? ?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;
? ? ? }
}


  附:Nginx 的安装方法可参照《Nginx 0.5.31 + PHP 5.2.4(FastCGI)搭建可承受3万以上并发连接数,胜过Apache 10倍的Web服务器》文章的以下段落(仅做负载均衡,无需支持PHP的安装方法):

  二、安装PHP 5.2.4(FastCGI模式)
  4、创建www用户和组,以及其使用的目录:

  三、安装Nginx 0.5.31
  1、安装Nginx所需的pcre库:
  2、安装Nginx
  3、创建Nginx日志目录
  5、启动Nginx

热点排行