Nginx Proxy Load Balancer--according to the access directory and according to the different Apache

Source: Internet
Author: User

first of all, according to the directory accessed to distinguish the back end of W eb:

My requirement: When the requested directory is/aaa/sends the request to machine A, when the requested directory is/bbb/sends the request to machine B, except the directory/aaa/and the directory/bbb/, the other request sends to machine B

The contents of my configuration file are:

  1. Upstream aaa.com

  2. {

  3. Server 192.168.111.6;

  4. }


  5. Upstream bbb.com

  6. {

  7. Server 192.168.111.20;

  8. }


  9. server {

  10. Listen 80;

  11. server_name li.com;

  12. location/aaa/

  13. {

  14. Proxy_pass http://aaa.com/aaa/;

  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/bbb/

  20. {

  21. Proxy_pass http://bbb.com/bbb/;

  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. Location/

  27. {

  28. Proxy_pass http://bbb.com/;

  29. Proxy_set_header Host $host;

  30. Proxy_set_header X-real-ip $remote _addr;

  31. Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;


  32. }


  33. }


Copy Code

Description:
more than 1 of the aaa.com and bbb.com in the configuration file are custom and write-free.
2 The server in upstream can write multiple, for example

Upstream aaa.com
{
server 192.168.111.6;
server 192.168.111.4;
server 192.168.111.5;
}

3 Proxy_passhttp://aaa.com/aaa/You must add this directory here, or you will have access to the root directory.
4 Actually, in the above configuration file, the localtion/bbb/part can be omitted, because the back location/already contains the/bbb/, so even if we do not define localtion/bbb/will also access to bbb.com.


Nginx proxies for the requested URI:

Scene: 1 nginx to proxy 4 Apache
Requirements: Proxy to different Apache according to different request URI

The Nginx configuration file is:


  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. }






Nginx Proxy Load Balancer--according to the access directory and according to the different Apache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.