萬盛學電腦網

 萬盛學電腦網 >> 服務器教程 >> nginx負載均衡配置-windows

nginx負載均衡配置-windows

  nginx負載均衡配置-windows

  雖然說windows上的nginx在官方文檔中提到"僅作為測試"之用,但對於小規模並發場景還是比apache有不小的優勢。所以,本文也將其作為windows服務器上負載均衡的主要工具進行說明。

  配置實例

  #user nobody;

  #指定nginx進程數,通常與CPU數相一致。特別是在windows平台中,這一數值一般只能設置為1.

  worker_processes 1;

  #error_log logs/error.log;

  #error_log logs/error.log notice;

  #error_log logs/error.log info;

  #pid logs/nginx.pid;

  events {

  # windows平台基本只能設置為1024

  worker_connections 1024;

  }

  http {

  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 off;

  #tcp_nopush on;

  keepalive_timeout 15;

  #gzip on;

  # HTTPS server

  upstream cas_servers {

  #使用C類網絡中的IP HASH方式進行負載分流

  ip_hash;

  server 127.0.0.1:8400 weight=1;

  server 127.0.0.1:8401 weight=1;

  # server 127.0.0.1:8402 weight=1;

  }

  server {

  listen 80;

  server_name 192.168.50.30;

  location / {

  proxy_pass http://127.0.0.1:9000$request_uri;

  proxy_set_header Host $host;

  proxy_set_header X-Real-IP $remote_addr;

  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  }

  }

  server {

  listen 443;

  server_name example.;

  ssl on;

  ssl_certificate ssl.crt;

  # 與apache類似,nginx也不使用有密碼的ssl key

  ssl_certificate_key ssl-nokey.key;

  ssl_session_timeout 5m;

  ssl_protocols SSLv2 SSLv3 TLSv1;

  #ssl_ciphers HIGH:!aNULL:!MD5

  ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

  ssl_prefer_server_ciphers on;

  #雙向認證

  #ssl_client_certificate ca.crt;

  #雙向認證

  ssl_verify_client off;

  location / {

  proxy_pass http://cas_servers$request_uri;

  # 將client端傳遞過來的HTTP Host轉發給給後端 Web AppServer

  proxy_set_header Host $host;

  # 傳遞client端的真實IP,但如果後端 Web AppServer 沒有對此進行專門處理,也沒啥作用

  proxy_set_header X-Real-IP $remote_addr;

  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  # 如果使用了 SSL,則將HTTP SSL_CERT 參數轉發給後端 Web AppServer

  proxy_set_header SSL_CERT $ssl_client_cert;

  }

  }

  }

copyright © 萬盛學電腦網 all rights reserved