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) | 阅读(213882)
南蛮虫
2012-10-12 15:51
学习 2009-3-11 20:41想问一下,为什么本机不能也接受访问呢?例如:a、b、c三台机器,我在a上面如同上面配置的,为什么访问总是在b、c来回换,为什么a上也有网站却不被访问到呢?如果我也想访问a服务器上的网站需要如何处理?同样遇到这个问题,大牛解析一下行不?
north face clearance Email Homepage
2012-11-8 09:51
Waterproof north face clearance and breathable, HyVent outer fabric protection 550 filled insulation, save in and fashion quilt confusing north face outlet locations place. Warm and comfortable wrapped in a fashionable flattering fit
游客
2012-11-13 10:22
grin,very good .
小小春
2012-11-13 17:53
大赞~~博主威武!
鸟菜小
2012-12-3 11:15
我做nginx遇到一个问题,就是一台A服务器nginx做前端,后端两台web服务器B,C,用的是ip hash负载均衡,为什么只分配到一台web B上呢?这样的负载均衡就没用了。
鸟菜小
2012-12-3 11:16
我做nginx遇到一个问题,就是一台A服务器nginx做前端,后端两台web服务器B,C,用的是ip hash负载均衡,为什么只分配到一台web B上呢?这样的负载均衡就没用了。
鸟菜小
2012-12-3 13:10
upstream  www.test.com  {
      ip_hash;
      server   172.16.1.143:80;
      server   172.16.1.193:80;
#      server   172.16.1.143 weight=6;
#      server   172.16.1.193 weight=4;

      }

server
     {
              listen  80;
              server_name  www.test.cn;

              location / {
                       root    /usr/share/nginx/html;
                       proxy_pass        http://www.test.cn;
                       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.test.cn  '$remote_addr - $remote_user [$time_local] $request '
#                                '"$status" $body_bytes_sent "$http_referer" '
#                                '"$http_user_agent" "$http_x_forwarded_for"';
              access_log  /usr/share/nginx/logs/cn_access.log ;
      }

这是前端A服务器的配置,后端的访问IP全是这台服务器的,我查了一下,是跟这的配置有关,想让后端的web服务器全是真实的访问IP。请帮我解决下,谢谢~!
GAWET
2013-1-29 16:49
买轴承就到:www.jkzhoucheng.cn
GAWERW
2013-3-1 15:42
买轴承就到:www.jkzhoucheng.cn
SDSD
2013-4-7 17:05
买轴承就到:www.jkzhoucheng.cn
weinan2087 Email
2013-4-11 16:49
谢谢分享,我配置nginx2天了,今天看到您的这篇发表我配置成功了。
django Email Homepage
2013-11-30 19:45
Uggs Sale the ideal idea Coach Outlet Online  enough time to search for many of reduction Ugg boot. Like big portions? If you began ready your apartment, Coach Outlet  it's always best to consider the most effective way direct to the stage it could be to utilise your inventory throughout Coach Factory Outlet  concern, or maybe you basically won't destination stuff not enough.we're anti- whitening tray because Coach Outlet Online  i will be enjoy just get germ dog breeders
ADSF
2013-12-31 15:58
买轴承就到:www.jkzhoucheng.cn
sm5uz43kgk Email Homepage
2013-12-31 17:01
广州峻康生物科技有限公司坐落在广东省广州市白云区。峻康生物在中国广州应用了世界尖端与科研技术,樱之秀家居彩装膜爱的收录,从农作物中分离提取纳豆激酶。峻康研发的纳豆激酶是一种有机化合物,广泛应用于医药保健,日用化妆品等行业,峻康品牌成熟走向世界,合作伙伴遍布世界各地,樱之秀家居彩装膜,科技引领了财富,樱之秀家居彩装膜幸福家装,专业缔造了奇迹!!
《总裁,老婆不好当》私事免费阅读 - 《小反扑阅读网》
正在埋头吃饭的小梁抬起头,笑着来了一句:“运气真好,你这真是贼不走空啊。”
禅猫 Email Homepage
2014-12-10 18:27
阿里的单机私网slb要怎样设置  谢谢 另我的环境是amh面板的 。。
kaka20099527
2015-4-16 10:00
张老师,nginx在你的项目中是用root启动的吗,一般应用级程序应该用非root用启动。
abc Email
2015-5-14 17:12
张老师,您好!
本机
a b c  3台 tomcat服务器  分别  占用  8081 8082 8083 端口
我怎么配置 访问
一个URL    负载均衡到 a b c
abc Email
2015-5-14 17:26
谢谢你的这篇文章 配置成功了  原来我没有应用 path="/xxx"
端口不能直接访问
shz Email
2022-6-2 15:12
I see some amazingly important and kept up to length of your strength searching for in your on the site  https://vintagekitchenar.com/
分页: 3/5 第一页 上页 1 2 3 4 5 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]