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.
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.
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 ")
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;