Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of APACHE and NGINX

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article shares with you the content of sample analysis of APACHE and NGINX. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Apache is currently the most popular Web application server, accounting for more than 70% of the Internet application server. It is not surprising that Apache has been so successful: it is free, stable and excellent, but another reason Apache has achieved such success is that when the Internet was just emerging, Apache was the first available Web application server and people had no other choice.

There is no denying that Apache is an excellent all-round Web server, but for those who need more powerful Web application servers (such as size, customizability, response speed, scalability, etc.), Apache obviously does not meet their requirements, and looking for a replacement for Apache is a better choice.

Nginx (pronounced engine x) is a lightweight Web server / reverse proxy server and e-mail (IMAP/POP3) proxy server and is distributed under a BSD-like protocol. Developed by Igor Sysoev, a Russian programmer, it is used by Russia's large portal website and search engine Rambler. It is characterized by less memory and strong concurrency ability. in fact, the concurrency ability of nginx does perform well in the same type of web server. Chinese mainland uses nginx website users: Sina, NetEase, Tencent and so on. Nginx can be compiled and run on most Unix like OS, and there is a portable version of Windows. The 1.4.0 stable version of Nginx was released on April 24, 2013. in general, for new sites, it is recommended to use the latest stable version as the production version, and existing sites are not urgent to upgrade. The source code for Nginx uses 2-clause BSD-like license.

Apachehttp server is the number one Web server software in the world. It can run on almost any wide range of Apache Server configuration interfaces, using computer platforms. Apache originated from the NCSAhttpd server and has become one of the most popular Web server software in the world after many modifications. Apache is taken from the pronunciation of "a patchy server", which means a server full of patches. Because it is free software, people are constantly developing new features, new features, and fixing old defects for it. Apache is characterized by simplicity, high speed, stable performance, and can be used as a proxy server.

Nginx (pronounced engine x) is a lightweight Web server / reverse proxy server and e-mail (IMAP/POP3) proxy server and is distributed under a BSD-like protocol. Its characteristic is that it occupies less memory and has strong concurrency ability. in fact, the concurrency ability of nginx does perform better in the same type of web server. At present, Chinese mainland uses nginx website users: Sina, NetEase, Tencent, and the well-known microblog Plurk also uses nginx.

Nginx start, restart, shut down command

Stop the operation

The stop operation is done by sending a signal to the nginx process (see the linux chapter for what a signal is)

Step 1: query the nginx main process number

Ps-ef | grep nginx

Look for the master process in the process list, and its number is the main process number.

Step 2: send a signal

Stop Nginx calmly:

Kill-QUIT main process number

Quickly stop Nginx:

Kill-TERM main process number

Force stop Nginx:

Pkill-9 nginx

In addition, if the pid file storage path is configured in nginx.conf, the file is stored in the Nginx main process number, if not specified, it is placed in the logs directory of nginx. With the pid document, instead of querying the main process number of Nginx, we send a signal directly to Nginx with the following command:

Kill-signal type'/ usr/nginx/logs/nginx.pid'

Smooth restart

/ usr/sbin/nginx

If you change the configuration, you have to restart Nginx. Do you want to close Nginx and then turn it on? No, you can send a signal to Nginx and restart smoothly.

Smooth restart command:

Kill-HUP residence title or process number file path

Or use the

/ usr/sbin/nginx-s reload

Note that after modifying the configuration file, it is best to check whether the modified configuration file is correct, so as to avoid errors in Nginx that affect the stable operation of the server after restart. The command to determine whether the Nginx configuration is correct is as follows:

Nginx-t-c / usr/nginx/conf/nginx.conf

Or

/ usr/nginx/sbin/nginx-t

Comparison between Apache and Nginx

1. The advantages of nginx over apache:

Lightweight, also a web service, takes up less memory and resources than apache

Anti-concurrency, nginx processes requests asynchronously and non-blocking, while apache is blocking. Under high concurrency, nginx can maintain low resources, low consumption and high performance.

Highly modular design, relatively simple to write modules

The community is active and all kinds of high-performance modules are produced quickly.

Advantages of apache over nginx:

Rewrite is more powerful than nginx's rewrite.

Dynamic page

There are so many modules that you can find anything you can think of.

Less bug, more bug in nginx

Super stable

Existence is the reason. Generally speaking, web services that require performance use nginx. If you don't need performance but stability, then apache. The functional modules of the latter are better than the former, for example, the module of ssl is better than the former, and there are many configurable items. It should be noted here that the epoll (kqueue on freebsd) network IO model is the fundamental reason for nginx's high processing performance, but not all cases are won by epoll. If only a few files provide static services, apache's select model may have higher performance than epoll. Of course, this is only an assumption based on the principle of the network IO model, and the real application still needs to be measured.

2. As a Web server: compared with Apache,Nginx, it uses fewer resources, supports more concurrent connections, and embodies higher efficiency, which makes Nginx especially popular with virtual host providers. In the case of high connection concurrency, Nginx is a good alternative to Apache servers: Nginx is one of the software platforms often chosen by web hosting bosses in the United States. Can support up to 50000 concurrent connections response, thank Nginx for choosing epoll and kqueue for us as the development model.

Nginx as a load balancing server: Nginx can not only directly support Rails and PHP programs to serve externally, but also support external services as HTTP proxy servers. Nginx is written in C, both the system resource overhead and the efficiency of CPU are much better than Perlbal.

As a mail proxy server: Nginx is also an excellent mail proxy server (one of the earliest purposes of developing this product is also as a mail proxy server), Last.fm describes the successful and wonderful experience.

Nginx is a very simple installation, configuration files are very simple (and can also support perl syntax), very few Bugs server: Nginx is very easy to start, and can almost do 7 hours 24 non-stop operation, even if it runs for several months without reboot. You can also upgrade the software version without interruption of service.

3. Nginx configuration is simple and Apache is complex.

The static processing performance of Nginx is 3 times higher than that of Apache.

It is relatively simple for Apache to support PHP, and Nginx needs to be used with other backends.

Apache has more components than Nginx

Now Nginx is the first choice of Web server.

4. The core difference is that apache is a synchronous multi-process model, with one connection corresponding to one process; nginx is asynchronous, and multiple connections (ten thousand levels) can correspond to one process.

5. Nginx handles static files well and consumes less memory. But there is no doubt that apache is still the mainstream at present, with many rich features. So it still needs to be matched. Of course, if you can determine that nginx is suitable for the demand, then using nginx will be a more economical way.

Due to the inherent deficiency that apache does not support multi-core processing, it is recommended to use nginx as the front end and apache as the back end. The cluster function of self-generation of nginx is used in large web sites.

6. From the personal past usage, the load capacity of nginx is much higher than that of apache. The latest server has also switched to nginx. And after changing the configuration of nginx, you can-t test whether there is any problem with the configuration. When apache restarts, you will find that there is something wrong with the configuration, which will collapse very carefully. Now you will be very careful when you change it. Now there are many cluster stations, front-end nginx anti-concurrency, back-end apache cluster, and it works well.

7. Nginx is a chicken to handle dynamic requests. Generally, dynamic requests need to be done by apache, while nginx is only suitable for static and reverse requests.

8. From my personal experience, nginx is a very good front-end server with good performance. It is easy to open nginx on Laoben and run 10000 configuration files with webbench model. Apache supports php and other languages very well. In addition, apache has a strong support network, which takes longer to develop compared to nginx.

9. Nginx is superior to apache in two main points: 1.Nginx itself is a reverse proxy server 2.Nginx supports 7-tier load balancing Of course, Nginx may support higher concurrency than apache, but according to NetCraft, in April 2011, Apache still accounts for 62.71%, while Nginx is 7.35%. Therefore, generally speaking, Aapche is still the first of most companies, because its mature technology and development community are already very good performance.

10. Your need for web server determines your choice. Nginx is superior to APACHE in most cases, such as static file processing, PHP-CGI support, reverse proxy functionality, front-end Cache, maintaining connections, and so on. In Apache+PHP (prefork) mode, if the PHP processing is slow or the front-end pressure is high, it is easy to see a surge in the number of Apache processes, resulting in a denial of service.

11. You can take a look at nginx lua modules: there are more modules in https://github.com/chaoslaw...apache than nginx, and it is most popular to implement apache directly with lua. Why? Most people don't bother to update to nginx or learn new things.

12. For nginx, I like that its configuration file is very concise, regular configuration makes a lot of things simple, efficient, takes up less resources, and the agent is powerful, so it is very suitable to be a front-end response server.

13. Apache has advantages in dealing with dynamics, Nginx concurrency is better, CPU memory footprint is low, if rewrite is frequent, it is still Apache.

Thank you for reading! This is the end of this article on "sample Analysis of APACHE and NGINX". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report