Wednesday, December 28, 2011

Apache vs NginX


Nginx is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption

Nginx is one of a handful of servers written to address the C10K problem. Unlike traditional servers, Nginx doesn't rely on threads to handle requests. Instead it uses a much more scalable event-driven (asynchronous) architecture. This architecture uses small, but more importantly, predictable amounts of memory under load.

Even if you don't expect to handle thousands of simultaneous requests, you can still benefit from Nginx's high-performance and small memory footprint. Nginx scales in all directions: from the smallest VPS all the way up to clusters of servers.

Nginx particularly excels at serving static files—like the Tectonicus map tile images. For larger websites, it's often employed as a front-end Web server to quickly dish up unchanging page content, while passing on requests for dynamic stuff to more complex Apache Web servers running elsewhere. However, I was interested in it purely as a fast single Web server.

http://joeandmotorboat.com/2008/02/28/apache-vs-nginx-web-server-performance-deathmatch/

http://www.wikivs.com/wiki/Apache_vs_nginx

Apache

The drawback to doing everything with processes is that Apache prefork can be a bit of a memory hog, especially under load. Another precompiled flavor of Apache can be installed as an alternative: Apache MPM worker. "Worker" differs from "prefork" in that worker's processes are multithreaded, giving them the ability to service more requests with fewer system resources. This can translate into faster pages served with less RAM and CPU. However, because some Apache modules don't necessarily work well when run under multithreaded Apache, you have to specifically select this version to install on Ubuntu and on other GNU/Linux distros with package management.

Alternatively we can use FastCGI with Apache to handle PHP requests. FastCGI can use a single persistent process which handles many requests over its lifetime

http://www.cyberciti.biz/tips/rhel-centos-fedora-apache2-fastcgi-php-configuration.html

Other Surveys for All Web Servers

http://news.netcraft.com/archives/2011/04/06/april-2011-web-server-survey.html

Friday, December 2, 2011

Apache Questions

Q1 How to enable Directory Listing

Ans Place "Options +Indexes" in Directory Tabs

Q2 Allow Apache to use / access symbolic links directory/files

Ans Place "Options +FollowSymLinks" in Directory Tabs

Q3 Allow Apache to use / access .htaccess file

Ans Place "AllowOverride All" in Directory Tabs

Q4 Can we replace .htaccess file to some other for our convenient

Ans Yes, change "AccessFileName .htaccess" to "AccessFileName .xyz"

Q5 Set default number of start processes

Ans Find "StartServers ..." and set as per your requirement

Q6 How to disable Apache signature/version

Ans ServerSignature Off

Q7 How to block/disable TRACE

Ans Use "TraceEnable Off" globally so that TRACE will be disabled for all VHOSTS

Q8 Best tools for monitoring Apache Requests

Ans use Apache Handler "server-status" and APACHETOP tool (its like TOP command in linux)

Q9 How can we protect our site to avoid DOS/DDOS attacks

Ans Use mod_evasive apache module or this can also be done through firewall

Q10 Redirect abc.com to www.abc.com

Ans Use following in abc.com VHOST : - "Redirect / http://www.abc.com/"

Q11 Which Apache processes are consuming higher memory

Ans Use ApacheTop or "ps -ylC httpd --sort rss" this command will show all apache processes in ascending order according to \memory size used by per process (RSS field)

Q12 What are different MPM's available in Apache for Linux and how they work

Ans There are 2 MPMs available 1) Worker 2) Prefork

     

        Worker :- This Multi-Processing Module (MPM) implements a hybrid multi-process multi-threaded server. By using threads to serve requests, it is able to serve a large number of requests with fewer system resources than a process-based server. However, it retains much of the stability of a process-based server by keeping multiple processes available, each with many threads.

The most important directives used to control this MPM are ThreadsPerChild, which controls the number of threads deployed by each child process and MaxClients, which controls the maximum total number of threads that may be launched

      Prefork :- This Multi-Processing Module (MPM) implements a non-threaded, pre-forking web server that handles requests in a manner similar to Apache 1.3. It is appropriate for sites that need to avoid threading for compatibility with non-thread-safe libraries. It is also the best MPM for isolating each request, so that a problem with a single request will not affect any other.

This MPM is very self-regulating, so it is rarely necessary to adjust its configuration directives. Most important is that MaxClients be big enough to handle as many simultaneous requests as you expect to receive, but small enough to assure that there is enough physical RAM for all processes.


Q13 Write a Rewrite rule to redirect (www).abc.com/request.php to www.abc.com/request1.php

Ans RewriteEngine On
       RewriteCond %{HTTP_HOST} ^abc.com$ [NC,OR]
       RewriteCond %{HTTP_HOST} ^www.abc.com$ [NC]
       RewriteRule ^/request.php$ http://www.abc.com/request1.php [L]

Q14 How many connections apache server can handle

Ans This completely depends on our server configuration mainly on RAM

        Max no. of connections = (Total Memory - Memory Used By System For Its use) / average single apache process size*

        *Average Single Apache Process Size : Can be find using "top" command or "ps -ylC httpd --sort rss"


To be continued....