Wednesday, October 15, 2014

Nginx v.s. Apache

[1] Blog: Nginx v.s. Apache (May 14th, 2014)
    Apache - spawns a new process for each request. In pre-forked mode, each process contains one thread; in worker Multi-process mode (not thread safe), each process contains multiple thread. Apache is process-driven.
    Nginx - creates a fixed number of processes at start (a rule of thumb is 1 process each CPU), each process is single-threaded. Each request is handled by a thread. Each thread can handle thousands of requests in sequence. Nginx is event-driven, asynchronous and non-blocking.

    Nginx can process php natively. But it does not support Python/Ruby etc. Nginx is much faster in serving static contents. A common configuration is use Nginx as proxy server in front of Apache back end server.


[2] http://www.thegeekstuff.com/2013/11/nginx-vs-apache/

Nginx v.s. Apache:
  • As discussed above Nginx is based on event-driven architecture. Apache is based on process-driven architecture. It is interesting to note that Apache in its earliest release was not having multitasking architecture. Later Apache MPM (multi-processing module) was added to achieve this.
  • Nginx doesn’t create a new process for a new request. Apache creates a new process for each request.
  • In Nginx, memory consumption is very low for serving static pages. But, Apache’s nature of creating new process for each request increases the memory consumption.
  • Several benchmarking results indicates that when compared to Apache, Nginx is extremely fast for serving static pages.
  • Nginx development started only in 2002. But Apache initial release was in 1995.
  • In complex configurations situation, when compared to Nginx, Apache can be configured easily as it comes with lot of configuration features to cover wide range of requirements.
  • When compared to Nginx, Apache has excellent documentation.
  • In general, Nginx have less components to add more features. But Apache has tons of features and provides lot more functionality than Nginx.
  • Nginx do not support Operating Systems like OpenVMS and IBMi. But Apache supports much wider range of Operating Systems.
  • Since Nginx comes only with core features that are required for a web server, it is lightweight when compared to Apache.
  • The performance and scalability of Nginx is not completely dependent on hardware resources, whereas the performance and scalability of the Apache is dependent on underlying hardware resources like memory and CPU.

[3] http://www.wikivs.com/wiki/Apache_vs_nginx
    Apache is like Microsoft Word, it has a million options but you only need six. Nginx does those six things, and it does five of them 50 times faster than Apache.

[4] Install Nginx: http://www.thegeekstuff.com/2011/07/install-nginx-from-source/

Summary of installation steps:

- download source code from: here. Or:

cd
wget http://nginx.org/download/nginx-1.0.5.tar.gz
tar xvfz nginx-1.0.5.tar.gz
cd nginx-1.0.5

- Install Nginx:
  ./configure --help
  ./configure
  make
  make install

  Note: if in the step of "./configure" you get a complaint that pcre is not available, then you can either install pcre, or do: "./configure –-without-http_rewrite_module"

- Change default listening port

# vi /usr/local/nginx/conf/nginx.conf
    server {
        listen       8081;
        server_name  localhost;
- Start Nginx server:

cd /usr/local/nginx/sbin
./nginx

After this you can query the nginx processes:

# ps -ef | grep -i nginx
root     18596 13:16 nginx: master process ./nginx
nobody   18597 13:16 nginx: worker process

Get version:

# ./nginx -v
nginx: nginx version: nginx/1.0.5

Read logs:

# ls /usr/local/nginx/logs/
access.log
error.log
nginx.pid

- Stop Nginx server:

cd /usr/local/nginx/sbin
./nginx -s stop


No comments:

Blog Archive

Followers