nginx测试小结

Posted itblock

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx测试小结相关的知识,希望对你有一定的参考价值。

最近在工作当中需要使用nginx,就对nginx进行进一步的了解,测试。

       工作需求是在微服务架构的基础上,客户端通过nginx反向代理访问服务端,确保当一个服务端出现问题时能及时切换到正常工作的服务端。测试使用nginx-1.13.2.rar,官网地址为:http://www.nginx.org/;测试使用的ip服务端为:10.74.214.109:8088、10.74.214.109:8091,服务端启动时的端口为8090;程序首页的路径为:"D:cloudCodeinternetCoreToolWebPortal1.CoreToolWebPotalWeb"下的index.html文件
  将nginx解压包放在C盘根目录下:
  编辑修改nginx.conf文件,如下:
 
  #Nginx用户组。windows下不指定;
  #user  nobody;
 
     #工作进程:数目。根据硬件调整,通常等于CPU数量,或者2倍于CPU;
     worker_processes  1;
 
     #pid        logs/nginx.pid;
 
 
   events {
        #每个工作进程的最大连接数量,根据硬件调整,和前面工作进程配合起来使用,尽量大,
        #但是别把CPU跑到100%就行。
        #每个进程允许的最多连接数,理论上没台nginx服务器的最大连接数       
        #为:worker_process*worker_connections
       worker_connections  1024;
       }
 
       #设定http服务器,利用它的反向代理功能提供负载均衡支持
       http {
           # 设定mime类型,类型由mime.type文件定义
           include       mime.types;
           default_type  application/octet-stream;
 
           #log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
           #                  ‘$status $body_bytes_sent "$http_referer" ‘
           #                  ‘"$http_user_agent" "$http_x_forwarded_for"‘;
 
           #access_log  logs/access.log  main;
 
           sendfile        on;
           #tcp_nopush     on;
 
           #keepalive_timeout  0;
           keepalive_timeout  65;
 
           #gzip  on;
 
           #负载均衡地址
           upstream  api_server{
                 #server 10.74.214.109:8091 weight=1 max_fail=3 fail_timeout=30;
                 server   10.74.214.109:8091;
                 server   10.74.214.109:8088 backup;#热备
           }
 
           server {
                 listen       8090;#备注:启动服务器的端口为这个;
 
                 #配置访问域名
                 server_name  localhost;
 
                 #charset koi8-r;
 
                 #access_log  logs/host.access.log  main;
 
                 location / {
                 root  "D:cloudCodeinternetCoreToolWebPortal1.CoreToolWebPotalWeb";
                 index  index.html index.htm;
          }
 
        #error_page  404              /404.html;
 
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
        # proxy the php scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ .php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
 
        # deny access to .htaccess files, if Apache‘s document root
        # concurs with nginx‘s one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
 
 
 
 
        #实现反向代理
        location ~* ^/services/.*{
             #请求的主机域名
             proxy_set_header  Host  $host;
             
             #转的目标ip   
             proxy_set_header  X-Real-IP  $Remote_addr;
 
 
             #转发的目标
             proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
 
             #禁止缓冲
             proxy_buffering  off;
 
             #代理地址
             proxy_pass   http://api_server;
 
       }
    }
 
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
 
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
 
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
 
}
 
 
      运行nginx:cmd->cd ../..->cd nginx-1.13.2->start nginx.exe
      由于时在公司测试的运行,公司出于保密需要截图不允许外发,暂不将测试的截图贴上,敬请谅解!

以上是关于nginx测试小结的主要内容,如果未能解决你的问题,请参考以下文章

性能测试方案和性能测试报告小结

软件测试方法小结

测试后台展示页小结

自动化测试Selenium Webdriver (JAVA)学习小结

软件测试863面试前小结

接口测试结束后的小结