Ngnix反向代理和负载均衡体验

admin 发表于 WEB, 网络技术 分类,标签: , ,
3

LNXI_CLUSTER_r1_c1

Nginx不用介绍了吧,以前写过一篇文章http://netseagull.blog.51cto.com/476768/124019这方面资料现在应该有很多了。

今天来体验下Nginx反向代理负载均衡

一、Nginx安装

我们用Windows版的把,官网有下载地址的,以前一般都用kevinworthington做的那个。现在网上大部分资料还在讲kevinworthington那个。官方网站下载地址。

下回来是个Zip文件,找个地方解压就行了(支持中文路径),双击那个nginx.exe就行了。至于使用方法,网上资料不多,不过官网有。

Nginx.exe的使用方法,Nginx Windows版使用方法:
cd nginx【进入目录】
start nginx【启动】

控制方法

nginx -s [ stop | quit | reopen | reload ]

例如:nginx -s stop

好了不多说了,下面看反向代理

二、反向代理的配置

配置文件在conf文件夹,这几个都是,nginx.conf是最主要的。

server {
        listen       [::]80;    #监控IPv6
        server_name  www.ncist.net.cn;   #这是域名

            location / {
            #root   html;
            #index  index.html index.htm;
            proxy_pass http://10.1.0.99;      #访问该域名反指到这个地址
        }

这就是最简单的使用了。

当然也可以使用基于文件名表达式的:

location ~ \.php$ {
           proxy_pass   http://www.google.com;
        }
#反问PHP文件,直接指到谷歌去

三、负载均衡的方法:

upstream www6_ncist_net_cn {       #构建一个集群
    server www.sogou.com weight=1; 
    server www.baidu.com weight=2;       #集群中服务器的IP 端口 权重
    server 192.168.0.1:8080 weight =4
    }
    server {
    listen          [::]80;
    server_name     www6.ncist.net.cn;     //虚拟主机域名
     
    location / {
      proxy_pass      http://www6_ncist_net_cn;
    }                                  #访问该域名指到集群去
    }

over~·


3 篇评论 关于 “Ngnix反向代理和负载均衡体验”

发表我的评论

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif 

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word