Background: There are two file services in our company. One is a traditional mode server that stores files directly and accesses files through Nginx. Another is to directly use ali Cloud’s OSS object storage. The starting point of this paper is that in the traditional mode of file service, the number of visitors is too large, resulting in a large bandwidth of the server, image loading slow. This article describes two solutions.

Solution 1: Configure nginx

Through nginx to solve the problem of slow image loading, more connections, broadband occupancy. You can perform the following simple configurations:

`limit_rate_after 300k; 'Single connection of single file before 300KB' limit_rate 300K; 'Limit download speed of a single connection to 300KB /s' limit_conn addr 4; 'A connection is limited to a maximum of four threads. This configuration is not recommended because some images cannot be loaded if multiple images need to be displayed. `limit_req zone=baism burst=5 nodelay; I can wait in the buffer area of Baism when a large number of requests suddenly burst. There are five locations in the buffer area, but I don't recommend using it either, because images can't load after I configure them.Copy the code

Summary: Maybe I don’t have a complete understanding of the basics of Nginx, but I think the broadband factor is all there, and the same file server can only be optimized by limiting client connections. So it is simply optimized for a long time without further research, and there are many files on our file server.

Scheme 2: Use Aliyun CDN

Content Delivery Network (CDN): when accessing the file server through the CDN, the CDN caches the file to the CDN. When accessing the file next time, the CDN directly obtains the file from the CDN cache server without obtaining the file from the file server. For detailed knowledge, please refer to Baidu.

Content Delivery Network (CDN) is a distributed Network composed of servers in different regions, which is established and covered on the bearer Network. Source station resources are cached to edge servers all over the country for users to obtain nearby, reducing the source station pressure.

According to the document, Ali Cloud has 2,300 + nodes in China, all of which are connected to 10-gigabit network adapter. The storage capacity of a single node reaches 40TB 1.5PB, the bandwidth load reaches 40Gbps and 200Gbps, and it has the bandwidth reserve capacity of 130Tbps. Therefore, we temporarily chose the CDN of Aliyun.

We encountered a problem after configuration according to the CDN document of Aliyun. After the domain name of CDN was successfully configured, we could not find the file on nginx, and directly ran out the 404 exception. After adding a configuration to nginx to resolve the CDN domain name execution file, file access is normal.

Conclusion:

If the number of files is not particularly large and the number of visits is not particularly large, you can solve some of the broadband pressure by configuring local Nginx, after all, this is free. If the volume of traffic can not, and the broadband pressure is large, then directly recommend the use of Ali Cloud CDN service, configuration is very simple. Our server is hosted in the telecom machine room with 100 MB shared broadband. Before the use of CDN, the downlink speed of the server network is basically 11M/s during 8:00 to 00:00 every day, and fluctuates between 1-5m/s after the configuration of CDN. Therefore, using CDN can still solve a large part of the problem.