Home > Article > Operation and Maintenance > The difference between nginx and haproxy
For soft loads, we all know that the mainstream solutions include LVS, Haproxy, and Nginx! So how do we choose between Haproxy and Nginx? Before answering this question, let me talk about their characteristics based on my personal experience!
##Haproxy Features
Supports TCP and HTTP protocols, working on network layer 4 and layer 7 Support Session sharing, Cookies guidance Support URL health detection Support 8 load balancing strategies Support heartbeat detectionNginx Features
Support Http protocol, working on network layer 7 Support port health detection Support powerful regular matching rules Support WebSocket Protocol Support Http CacheDescription:
For Http protocol, Haproxy processing efficiency is higher than Nginx. Therefore, when there are no special requirements or general scenarios, it is recommended to use Haproxy for HTTP protocol load! But if it is the Web, it is recommended to use Nginx! In short, everyone can make a reasonable choice based on the characteristics of their respective usage scenarios! Last time someone asked me: Can the number of connections of Nginx or Haproxy break through the "curse" of "65535"? In fact, everyone has such questions because they don’t understand the working principle of Nginx or Haproxy! The following takes the Linux server as an example to explain the theoretical maximum number of connections between the two:Theoretical maximum number of connections for Nginx on Linux
Correct Reverse proxy: Maximum number of connections = work_processes * worker_connections Reverse proxy: Maximum number of connections = work_processes * worker_connections / 4
Note: worker_connections refers to the maximum number of connections that a single process can handle. Assume that your server has 8 cores. worker_connections =
65535 (can be customized, but the maximum number of file descriptors cannot be exceeded, because 1 connection is equivalent to using 1 file descriptor)
Theoretical maximum number of connections for Haproxy on Linux
Maximum number of connections = maxconn(global | defaults | listen )For more Nginx related technical articles, please visit theNginx usage tutorial column to learn!
The above is the detailed content of The difference between nginx and haproxy. For more information, please follow other related articles on the PHP Chinese website!