美文网首页
[Nginx]nginx反向代理集群配置

[Nginx]nginx反向代理集群配置

作者: w_w_wei | 来源:发表于2019-04-09 09:06 被阅读0次

在程序固定之后, 不对程序优化,使用固有配置的设备,
提高并发的有效手段是添加硬件配置。

创建一个网站并测试QPS

先使用docker创建一个php网站。

  1. 创建目录 ~/Program/test
  2. 添加文件 index.php
<?php
      phpinfo();
  1. 创建容器

docker run -d -v ~/Program/test:/webwww/public --name web1 -p 8081:80 ssslocal/nginx-php7

  1. 访问


  2. ab工具进行测试

$ ab -c 100 -n 10000 http://localhost:8081/                                 [23:08:11]
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
......
Server Software:        nginx/1.10.3
Server Hostname:        localhost
Server Port:            8081

Document Path:          /
Document Length:        77452 bytes

Concurrency Level:      100
Time taken for tests:   30.652 seconds
Complete requests:      10000
Failed requests:        1052
   (Connect: 2, Receive: 0, Length: 1050, Exceptions: 0)
Non-2xx responses:      6
Total transferred:      775965086 bytes
HTML transferred:       774055260 bytes
Requests per second:    326.24 [#/sec] (mean)
Time per request:       306.520 [ms] (mean)
Time per request:       3.065 [ms] (mean, across all concurrent requests)
Transfer rate:          24721.97 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1  29.0      0    1097
Processing:     5  304  25.8    301     561
Waiting:        5  303  25.7    300     560
Total:          5  305  40.1    301    1490
......

可以看到QPS326

组建一个nginx反向代理集群

  1. 使用容器创建第二个网站

docker run -d --name web2 -v ~/Program/test:/webwww/public
-p 8082:80 ssslocal/nginx-php7

  1. 添加集群配置文件
    • 先获取配置
    $ docker run --name tmp-nginx-container -d nginx
    $ docker cp tmp-nginx-container:/etc/nginx/nginx.conf ~/Program/test/nginx.conf
    $ docker rm -f tmp-nginx-container
    
    修改配置 nginx.conf 本次测试无需修改
    添加配置, ~/Program/test/default.conf
    upstream hello{
        server web1:80 weight=1;
        server web2:80 weight=1;
    }
    server {
        listen  80;
        server_name  www.if404.com;
        access_log /var/log/nginx/access.log main;
        error_log /var/log/nginx/error.log error;
        location / {
               proxy_set_header  Host  $http_host;
                proxy_set_header  X-Real-IP  $remote_addr;
                proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
               proxy_pass  http://hello;
        }
    }
    
  2. 启动一个集群nginx容器

docker run -d --name web -v ~/Program/test/default.conf:/etc/nginx/conf.d/default.conf --link web1:web1 --link web2:web2 -p 8083:80 nginx

验证

$ ab -c 100 -n 10000 http://localhost:8083/                                  [0:10:32]
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
......
Server Software:        nginx/1.15.9
Server Hostname:        localhost
Server Port:            8083

Document Path:          /
Document Length:        77705 bytes

Concurrency Level:      100
Time taken for tests:   29.604 seconds
Complete requests:      10000
Failed requests:        9098
   (Connect: 0, Receive: 0, Length: 9098, Exceptions: 0)
Non-2xx responses:      5
Total transferred:      778581151 bytes
HTML transferred:       776671296 bytes
Requests per second:    337.80 [#/sec] (mean)
Time per request:       296.035 [ms] (mean)
Time per request:       2.960 [ms] (mean, across all concurrent requests)
Transfer rate:          25683.86 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.4      0       6
Processing:     9  295 105.7    302     567
Waiting:        9  292 105.5    300     563
Total:          9  295 105.6    303     567
......

可以看到QPS337

相关文章

  • Nginx应用场景

    反向代理,负载均衡,动静分离 1.反向代理 修改nginx配置,并重新加载 重新加载nginx配置./nginx ...

  • 01-nginx前端方向代理

    前端反向代理 1.下载nginx 2. 配置nginx.conf反向代理

  • 第十九周作业

    1、搭建Tomcat集群,并通过nginx反向代理访问 反向代理示意图 测试环境: Nginx: 172.16.1...

  • nginx

    nginx的配置、虚拟主机、负载均衡和反向代理一nginx的配置、虚拟主机、负载均衡和反向代理二nginx的配置、...

  • nginx反向代理

    什么是反向代理 如何实现反向代理 准备工作以及安装nginx 配置nginx nginx的初始配置文件去掉注释后的...

  • nginx学习目录

    nginx安装部署和配置管理 nginx日志配置 nginx平滑升级与回滚 nginx反向代理 nginx负载均衡...

  • Nginx 负载均衡/反向代理配置

    反向代理: 修改nginx配置nginx.conf文件: 在location /{ #...

  • 第二课 nginx+tomcat集群

    正向代理,反向代理 配置Nginx 配置文件目录:/usr/local/nginx-1.6.1/conf/ngin...

  • nginx+tomcat集群

    正向代理,反向代理 配置Nginx 配置文件目录:/usr/local/nginx-1.6.1/conf/ngin...

  • nginx+tomcat集群

    正向代理,反向代理 配置Nginx 配置文件目录:/usr/local/nginx-1.6.1/conf/ngin...

网友评论

      本文标题:[Nginx]nginx反向代理集群配置

      本文链接:https://www.haomeiwen.com/subject/rnimiqtx.html