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 由于時在公司測試的運行,公司出于保密需要截圖不允許外發,暫不將測試的截圖貼上,敬請諒解!轉載于:https://www.cnblogs.com/ITBlock/p/9886469.html
總結
- 上一篇: 在性能测试时使用nmon进行监控服务器性
- 下一篇: BZOJ 4627: [BeiJing2