#配置代理 #===================================== #反向代理1 server{ listen 89; server_name localhost; #重寫后端服務器的location和refresh頭 #proxy_redirect on; location / { proxy_pass http://192.168.2.112:8080/; index index.html index.htm; } } #反向代理2 server{ listen 86; server_name localhost; proxy_redirect off; location / { proxy_pass http://127.0.0.1:8011; index index.html index.htm; } } #===================================== #===================================== #配置正向代理 server{ listen 88; resolver 114.114.114.114; location / { proxy_pass http://$http_host$request_uri; } } #配置https正向代理 #curl -l --proxy 192.168.2.108:443 www.baidu.com server{ resolver 114.114.114.114; listen 443; location / { proxy_pass https://$host$request_uri; proxy_buffers 256 4k; } } #===================================== #===================================== #配置負載均衡 upstream myFuzaiTest{ #四種均衡方式。 輪詢; weight:權重 ;ip_hash:每個請求會固定一個服務器 ; fair :第三方,按服務器響應時間優先分配(url_hash 按url的hash結果來分配)。 server 127.0.0.1:8011 weight=3; server 127.0.0.1:90 weight=1; } server{ listen 8077; server_name localhost; location / { proxy_pass http://myFuzaiTest; #proxy_set_header Host $host;#將請求頭轉發給后端服務器 #proxy_set_header X-Forward_For $remote_addr;#后端的Web服務器可以通過X-Forwarded-For獲取用戶真實IP } } #=====================================