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:

引用
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  application/octet-stream;

      keepalive_timeout 120;

      tcp_nodelay on;

      upstream  www.s135.com  {
              server   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  www.s135.com;

              location / {
                       proxy_pass        http://www.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  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        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
纯粹技术 | 评论(8) | 引用(0) | 阅读(5086)
chen Email Homepage
2007-10-30 09:21
不错!!非常好的一个软件!
hoho
2007-11-1 11:16
写的好   请问 如果 负载均衡后面的机器都是要用到session 的话   如何很好的解决这个问题呢?
laoheimao
2007-11-1 17:47
F5 有没有类似的负载均衡功能? 另外还有一个疑问:
客户端直接访问web服务器时,可以用HTTP_CLIENT_IP、REMOTE_ADDR 这几个变量看到客户端的IP
经过squid或者ngrnx之后,还能看到客户端的IP吗? 是不是要用HTTP_X_FORWARDED_FOR
张宴 回复于 2007-11-1 20:25
F5 BIG-IP 就是用来做负载均衡的。
经过squid或者ngrnx之后,看到客户端的IP,请用HTTP_X_FORWARDED_FOR
itsea
2007-11-1 22:30
谢谢张老大的好文,小弟请教几个问题
1、如果均衡的域名中有泛域名,或有几百个域名的话可以配置吗?
2、ngnix在做均衡的时候是否已经包含了cache功能?
3、ngnix---squid----apache取的的HTTP_X_FORWARDED_FOR是squid服务器的ip地址,如果想取真实客户端地址可以做到吗?
张宴 回复于 2007-11-1 23:15
1、nginx.conf
server_name  .s135.com;   即可支持***.s135.com泛域名

2、nginx负载均衡只做反向代理,有简单的缓冲,但不像Squid那样将cache存在本机。

3、我已经在nginx.conf配置文件中增加:
proxy_set_header   Host             $host;
proxy_set_header   X-Real-IP        $remote_addr;
proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

编译squid时加上--enable-follow-x-forwarded-for
然后在squid.conf中输入一行:
follow_x_forwarded_for allow all

后端的Apache取日志(httpd.conf):
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %h %T" combined
取到的就是用户真实IP
xyxj
2007-11-3 00:51
这个软件是不错,但是有一个硬伤
做负载均衡时,好像无法检测节点健康状态?
tclwp
2007-11-9 17:42
follow_x_forwarded_for allow all
全开是不是会引起安全问题?
tclwp on www.linuxforum.net
zhangbin
2008-5-12 17:43
请问,NGINX是不是基于域名的负载均衡
能不能基于IP做负载均衡
Dewei Email
2008-7-23 11:26
proxy_set_header   Host             $host;
                      proxy_set_header   X-Real-IP        $remote_addr;
                      proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
请问这三个是什么意思啊?
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]