Home > Article > Operation and Maintenance > How to build a picture and video server with Nginx
First of all, two stories:
Several years ago, when I was working in my last company, my work computer was not It is really uncomfortable to connect to the external network and develop the internal network. When checking any information, I can only use my mobile phone. What I can't do is find the code and I can only type it one by one.
One day, we received a customer and wanted to show him a promotional video for our new product, but the video had just been finished and was still on the intranet. They were sitting in the conference room chatting and waiting to watch it. Video, our boss came out to get the video, holding his laptop, dumbfounded, the video was on the intranet, and all USB ports were blocked on the desktop. It's so urgent that I don't know what to do. To get something from the intranet, I need to go through multiple levels of email approval. At this time, I stepped forward and used nginx to forward the video to the external network through the port opened by us and the three-party joint debugging. The customer was very happy after watching it. As a result, I was criticized and told that I did not comply with the company's procedures. In the end, my boss took the responsibility. . . The process was wonderful, but the results were not so great.
Another time, I was working for a company later, which was engaged in car loan business. The user information page displayed the person, car, invoice, and driving license. The mess adds up to displaying more than 50 pictures. The uploads are uploaded by customers, but the operation has to check the photos for approval on the approval page. Today's mobile phones are very good, and the cameras are all 7M or 8M. The image display alone on a page takes 400M, and this is for one user. At that time, the images were stored on Alibaba's OSS, and downloading was extremely slow. At this time, the boss was unhappy. It took the operation staff five minutes to approve one person's information and four and a half minutes to wait for the picture to load. What does technology do? Then the pressure came to the front-end guys to compress the images when uploading them. But when it reaches about 2M3M at most, I can’t go any further. After studying hard for several days, I accidentally heard it. I said, wouldn’t it be beautiful to use nginx? Just build a local static resource server and save the pictures locally. Direct intranet access is not very fast. The boss is also very happy, and it is very comfortable to just do it like this, but the problem is that the server has a 1T disk and a large number of users. It may be full in a few days. But within a few days, the state cracked down on small loan companies, users did not repay, and the company disappeared before the servers were full. The process was wonderful, but the result was even worse, but I don’t blame it this time.
Let me briefly introduce these two deployment steps.
This is simple, just configure it, but please note that gzip compression is useless for resources such as pictures and videos. If it is turned on, it will not reduce the size and occupy the CPU. resource. For demonstration purposes here, the image files are directly placed under html.
server { listen 8081; server_name somename alias another.alias; location /image { root html; autoindex on; } }
Direct address plus port plus file name access
139.155.71.11:8081/image/test1.jpeg
There are a few things you need to pay attention to
If you want to play it in chrome, the video encoding must be H264 , the others are all black screens with only sound and no images.
Need to add mp4 module
Back up nginx configuration file, Note, be sure to back it up. You will be sad if you lose it during make.
Execute the following command in the decompression directory of nginx. Of course, if there are other modules, you must also add them together and execute them.
./configure --with-http_mp4_module
Then
make make install
Put the backup configuration file and restart nginx
server { listen 8082; server_name somename alias another.alias; location /video { root html; mp4; mp4_buffer_size 1m;#处理mp4初始内存大小 mp4_max_buffer_size 50m;#处理mp4最大内存大小 limit_rate 150k; #限速 limit_rate_after 20m; #在20m后限速 } }
You can access the video you want by adding the access address, port and file name.
139.155.71.11:8082/video/test4.mp4
The video effect is as follows:
The above is the detailed content of How to build a picture and video server with Nginx. For more information, please follow other related articles on the PHP Chinese website!