nginx針對請求的uri來代理

場景:1臺nginx去代理4臺apache
需求:根據不同的請求uri 代理到不同的apache

nginx的配置文件爲:


  1.     upstream aa.com {         

  2.                       server 192.168.0.121;

  3.                       server 192.168.0.122;  

  4.      } 


  5.     upstream bb.com {  

  6.                        server 192.168.0.123;

  7.                        server 192.168.0.124;

  8.         } 

  9.     server { 

  10.         listen       80; 

  11.         server_name  www.abc.com;

  12.         location ~ aa.php

  13.         { 

  14.             proxy_pass http://aa.com/; 

  15.             proxy_set_header Host   $host; 

  16.             proxy_set_header X-Real-IP      $remote_addr; 

  17.             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

  18.         } 


  19.          location ~ bb.php

  20.         {

  21.               proxy_pass http://bb.com/;

  22.               proxy_set_header Host   $host;

  23.               proxy_set_header X-Real-IP      $remote_addr;

  24.               proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  25.           } 

  26. }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章