Question about Synchronous File Upload by nginx Server Load balancer-SegmentFault

Source: Internet
Author: User
Tags file url
Dear friends, I have a problem now. Let me see: Because nginx is used for load balancing and requests are distributed to different servers, in this way, if you only want to save the uploaded image to one server, a problem occurs. Baidu's method: the first method is to use ftp in the code to synchronize files to the storage server... I have a problem. Let me take a look:
Because nginx is used for load balancing, as requests are distributed to different servers, a problem occurs if you only want to save the uploaded images to one server.
Baidu's method:
The first method is to use ftp in the code to synchronize files to the storage server.
The second method is to use curl to submit the file to the storage server and save it again.
The third method is to directly use the ip address of the storage server to call the interface. The third method is not considered here.
I don't know how this kind of requirement is met.

Reply content:

Dear God, I have a question. Please help me to see it:
Because nginx is used for load balancing, as requests are distributed to different servers, a problem occurs if you only want to save the uploaded images to one server.
Baidu's method:
The first method is to use ftp in the code to synchronize files to the storage server.
The second method is to use curl to submit the file to the storage server and save it again.
The third method is to directly use the ip address of the storage server to call the interface. The third method is not considered here.
I don't know how this kind of requirement is met.

  • 3 hours ago
  • Comment
  • Reply

Please log on first and then comment

Sort by default

Two answers

The answer is helpful to people and has reference value.0The answer is not helpful. It is a wrong answer.

  1. The nginx of the host performs special processing on the uploaded location, allowing only one machine to upload files. This solution is not perfect but effective and can be used as an excessive solution for a period of time.

  2. Build a distributed file system and mount it to all servers. After processing files uploaded, write only to this specific directory, in nginx, define a location to point to this directory (for example,/data/upload). The disadvantage is that you need to maintain an extra Distributed File System (like your first idea, however, distributed file systems do not require "synchronization ")

  3. You can use external CDN File Upload to solve this problem.

1. Dedicated servers are used to store these static resources;
2. Make several disks into network disks (nfs), which are used to store these files. Each server mounts these disks, which is similar to windows shared folders;
3. After the upload is successful, a File url is returned. This url is the file address;

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.