Something is usually created to solve some problem, and in the case of Nginx, this is also true.
For example, you wrote a small website out of boredom, and after deploying it to Tomcat, you can access it. In this case, your site will have very few users and will not have high concurrency. In this case, a JAR package will be enough to start the application and internal Tomcat will return the content to the user.
But later, your small website because the content is very attractive gradually fire, more and more users, concurrent volume also slowly increased, at this time a server has been unable to meet the needs of the website.
You can’t afford to let your kids get overwhelmed, so you spend money on more servers.
But the problem comes, there are many servers, such as user 1 through the first server 1 login, but later requests to server 2, is not logged in, this is obviously not good. So we need a proxy server to forward and process requests for us. And here comes Nginx.
What is Nginx
Engine X (Nginx) is a high-performance HTTP and reverse proxy Web server that provides IMAP, POP3, and SMTP mail services.
It is characterized by low memory consumption, strong concurrency, and very documented operation. It can almost do 7×24 uninterrupted operation, even if it runs for several months, it does not need to restart. Moreover, the software version can be upgraded without interruption of service.
Nginx code is written entirely in C, and official data tests show that it can support responses with up to 50,000 concurrent connections.
Once you look at Nginx this is great, add it to your application.
Reverse proxy
If it’s called a reverse proxy, what is a forward proxy?
Forward proxy let’s say you want to visit Google to look up some technical issues, but you can’t get there because of the wall. After a baidu search, you found a XX browser plug-in that can serve as a ladder for you to climb up and see the outside world. This plug-in is a forward proxy, you know what it does and you actively use it for your purpose.
A reverse proxy is different from a forward proxy in that the forward proxy user is aware. A reverse proxy server is insensitive to users. The reverse proxy server is between the user and the target server. For users, the reverse proxy server is equivalent to the target server.
They add Nginx to small sites using reverse proxies.
Load balancing
There are now several servers, as well as proxy servers. But because you have a limited budget, the configuration of several additional servers has a high bottom, at this time if you can make the configuration of the high server to bear more pressure, let the configuration of the low point to bear less pressure.
Nginx load balancing can fulfill this requirement.
1. The polling
Polling is the process by which incoming requests visit the server in turn.
2. Weighted polling
Weighted polling, which distributes the number of requests on each server according to different weights.
3. iphash
Iphash hashes the IP address requested by the client, and then distributes the request from the same client IP address to the same server for processing based on the hash result. In this way, the session is not shared.
4. Separation of noise and movement
Some of the requests in your small site need to be processed in the background, but some of the requests are not required, such as CSS, HTML, JPG, JS, etc. These are collectively called static files.
Nginx can separate constant resources from frequently changing resources according to certain rules. After splitting, we can cache static resources according to their characteristics, thus improving the speed of resource response.
OK, through static and static separation, your small website response speed also up, the user experience is better, you finally breathe a sigh of relief.