ningx

官方测试nginx能够支支撑5万并发链接

 

1、http服务器。Nginx是一个http服务可以独立提供http服务。可以做网页静态服务器。

2、虚拟主机。可以实现在一台服务器虚拟出多个网站。

3、反向代理,负载均衡。

 

优点

可以不暴露真实服务器IP地址

 

PS--栗子

 配置静态访问(例如images, html page。nginx可以通过不同的配置,根据request请求,从本地的目录提供不同的文件返回给客户端)

server {

        listen       80;

        server_name  localhost;

        location / {

            root   html;

            index  index.html index.htm;

        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

}  

 

反向代理

 

    server {

        listen       80;

        server_name  8080.itmayiedu.com;

        location / {

    proxy_pass  http://127.0.0.1:8080;

index  index.html index.htm;

        }

    }

     server {

        listen       80;

        server_name  b8081.itmayiedu.com;

        location / {

    proxy_pass  http://127.0.0.1:8081;

index  index.html index.htm;

        }

    }

 

负载均衡

1)轮询

upstream backserver{

server 192.168.0.14; 
server 192.168.0.15; 

}

2)指定权重

upstream backserver { 
server 192.168.0.14 weight=10; 
server 192.168.0.15 weight=10; 

 

设置超时时间,宕机轮询配置

server {

        listen       80;

        server_name  www.itmayiedu.com;

        location / {

    proxy_pass  http://backserver;

index  index.html index.htm;

proxy_connect_timeout 1;

            proxy_send_timeout 1;

            proxy_read_timeout 1;

        }

 

}

 

nginx 解决跨域问题---做一个网关

server {

        listen       80;

        server_name  www.itmayiedu.com;

        location /A {

    proxy_pass  http://a.a.com:81/A;

index  index.html index.htm;

        }

location /B {

    proxy_pass  http://b.b.com:81/B;

index  index.html index.htm;

        }

    }

 

防盗链

location ~ .*\.(jpg|jpeg|JPG|png|gif|icon)$ {

        valid_referers blocked http://www.itmayiedu.com www.itmayiedu.com;

        if ($invalid_referer) {

            return 403;

        }

}

 

利用nginx 限制请求速度 防止DDOS

limit_req_zone $binary_remote_addr zone=one:10m rate=30r/m;

server {

...

location /login.html {

limit_req zone=one;

...

}

}

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值