1. 程式人生 > >nginx測試小結

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:\cloudCode\internet\CoreToolWebPortal\01.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:\cloudCode\internet\CoreToolWebPortal\01.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       由於時在公司測試的執行,公司出於保密需要截圖不允許外發,暫不將測試的截圖貼上,敬請諒解!