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

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

  用户访问http://blog.zyan.cc,将其负载均衡到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.zyan.cc  {
              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.zyan.cc  {
              server   192.168.1.7:8080;
              server   192.168.1.7:8081;
              server   192.168.1.7:8082;
      }

      server
      {
              listen  80;
              server_name  www.zyan.cc;

              location / {
                       proxy_pass        http://www.zyan.cc;
                       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.zyan.cc;

              location / {
                       proxy_pass        http://blog.zyan.cc;
                       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





技术大类 » Web服务器 | 评论(97) | 引用(0) | 阅读(213665)
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;
请问这三个是什么意思啊?
ttplay
2008-9-17 22:10
有请张兄指教:

server1与server2都安装web.
为了省下一台主机.在server1上安装nginx, 做反向代理, 轮循到server1, server2的web上实现负载均衡.
请问这样做与单独使用一台server3做负载均衡器的区别是不是非常大?

谢谢
ming
2008-11-12 10:31
我想问下,转发到后端那几台服务器,程序怎么同步?假如PHP呢,
todayboy
2008-12-21 13:07
做负载均衡时,好像无法检测节点健康状态?
学习
2009-3-11 20:41
想问一下,为什么本机不能也接受访问呢?
例如:a、b、c三台机器,我在a上面如同上面配置的,为什么访问总是在b、c来回换,为什么a上也有网站却不被访问到呢?如果我也想访问a服务器上的网站需要如何处理?
学生
2009-5-18 10:55
诚心请教,在php-fpm模式下,
可以做一组
      upstream  blog.s135.com  {
              server   192.168.1.7:8080;
              server   192.168.1.7:8081;
              server   192.168.1.7:8082;
      }
负载均衡么?
我查阅了一些资料,好像php-fpm同时只能打开一个端口,如果想实现可行么?
yiguihuo
2009-9-24 20:34
include       conf/mime.types;
引用mime.types文件的路劲前面应该不用加conf/,指定的类型文件应该自动会到conf目录中去找
游客
2009-10-19 17:54
grin
higkoo Email Homepage
2010-6-21 23:33
请教一下,经过Nginx转发后,是不是会转Http1.1损失为Http1.0?
图图
2010-8-31 17:07
proxy_set_header   Host             $host;                      proxy_set_header   X-Real-IP        $remote_addr;                      proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;请问这三个是什么意思啊?能具体讲一下么
阿甘
2010-11-10 11:05
安装php必须要用fastcgi模式吗?我用的是fpm的,但发现做负载均衡的时候发现访问/message/目录下的php文件的时候总是失效,系统自动在/下面去访问了,不知是什么原因的?
阿甘
2010-11-15 17:15
问题至今也没有找到原因的,有知道的么?
阿甘
2010-11-15 17:39
解决了,刚开始准备将负载均衡器也做为web使用,启用了以下代码 ,将这几行删除即可.         location ~ \.php$ {             root           html;             fastcgi_pass   127.0.0.1:9000;             fastcgi_index  index.php;             fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;             include        fastcgi_params;         }
分页: 1/5 第一页 1 2 3 4 5 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]