Home  >  Q&A  >  body text

nginx - Questions about download server traffic balancing?

How to solve the following requirements?

There are three nginx servers

One of the X's is used as a web server

The other two attachment servers are A and B, each of which saves different attachment files.
A and B are respectively bound to the domain name:
download-a.xxx.com
download-b. xxx.com

If the user needs to download a file 123.zip after visiting the website,
The download link is http://bbs.xxx.com/123.zip (note that it is not the real download address)

But I don’t know which server A or B this 123.zip file is placed on.
The real download address may be download-a.xxx.com/123.zip or download-b.xxx.com /123.zip
may not even have this file

Requirements and purposes: Since the export bandwidth of A and B is limited, the files are placed on different machines, while the bandwidth and storage space of A and B are effectively utilized (if the files on A and B are the same, load balancing is used method, and it will waste the disk space of A and B to save the file repeatedly). We hope to find where the file is through judgment, and let the storage server directly send the file to the client

Question 1:
If I use the PHP code of the website to determine which server the file is on, A or B, and then the page displays the real address, and the customer clicks to download it directly, how do I write the PHP code?

Question 2:
If the above method is not feasible, can an nginx server C be used in front of A and B to process the request, which is equivalent to the reverse proxy role

For example
The user clicks the resource link http://bbs.xxx.com/123.zip on the page to download. http://bbs.xxx.com is the domain name bound to server C. C itself does not Store data.
After receiving the request, C determines where the data is at A or B. If it is at A, C directly tells A that it is at your place, and asks A to send the file directly to the user without going through C. Can the above requirements be achieved by nginx? Woolen cloth?
The most important thing is to let the target server return the file directly to the user's browser. Is it possible to achieve this without using C's traffic and bandwidth?

为情所困为情所困2713 days ago409

reply all(1)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-16 17:24:10

    You can withdraw the storage location in the file name, for example, setting the xth bit means it is stored on the A/B server.

    Just judge based on the file name.

    reply
    0
  • Cancelreply