Use Nginx to build a simple image server in Linux

Source: Internet
Author: User

Use Nginx to build a simple image server in Linux

Recently, I have been asked how to upload images. Which of the following solutions are better? I have also seen some practices for uploading images, but they are not the best, let's talk about the general idea of using Nginx to upload images and image servers.

For personal projects or small enterprise projects, the following solutions can be used:

When you access the system and use the image upload function, the image is uploaded to the tomcat server where your current project is located. Under/image, you can directly access

Http: // ip: port/project/images/xxx.jpg

In this way, when there are few users, there is no problem.

 

When your enterprise develops and the business volume increases, the project you use starts to grow and the system speed slows down, you should consider the cluster, right?

So good. Suppose you have added tomcatB, and the performance has improved a little. The image has been uploaded successfully, and load balancing has been done. Suppose the image has been uploaded to tomcatA (unknown to users)

During the second access (the session stickiness and non-stickiness are not taken into account first, assuming the session is shared), the user accesses tomcatB, and the picture is gone, which is a big cross,

My God! What did you do? The image you just uploaded is gone,

Refresh the page! Again? What is the situation?

The background knows what is going on, but the user does not know !!!

 

The solution is as follows: tomcatA and B are uploaded to the image server. This user only accesses the path of the image server during the request, so there is no problem.

Someone may ask what to use to build the image server?

Tomcat? Yes, but tomcat mainly processes jsp better. image files are static resources, and the processing performance is average.

Apache? Yes. It is developed in pure C language, but it is not good enough.

Nginx? By the way, this is a popular reverse proxy server, I have briefly introduced in the previous article (http://www.cnblogs.com/leechenxiang/p/5327086.html)

In theory, a single machine is capable of sending up to 50 thousand sub-computers, which is very embarrassing. The actual test is about 2 W.

After installing the following solution, the image server will not be a problem,

 

Of course, after uploading images, you need to save the image path address to the database ~~

I have seen that the scheme for uploading images in an e-commerce system is similar to 1. It's okay to do this,

However, the image is uploaded to a field in a table in MySQL. Oh, my God!

How can we do this? Besides, the database does not have a database/table sharding index. Well, this is also a slot for me. Who told me to be involved?

Well, it's all about theory. The next article will explain how to do it.

Create a virtual static server using Nginx

For more Nginx tutorials, see the following:

Deployment of Nginx + MySQL + PHP in CentOS 6.2

Build a WEB server using Nginx

Build a Web server based on Linux6.3 + Nginx1.2 + PHP5 + MySQL5.5

Performance Tuning for Nginx in CentOS 6.3

Configure Nginx to load the ngx_pagespeed module in CentOS 6.3

Install and configure Nginx + Pcre + php-fpm in CentOS 6.4

Nginx installation and configuration instructions

Nginx log filtering using ngx_log_if does not record specific logs

Nginx details: click here
Nginx: click here

This article permanently updates the link 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.