How to boost your webserver performance?

       Loading time is one of the major concerns for many of the website owners. Nowadays it’s a basic business requirement just the way infrastructure oremployeestoabusiness.

      Communication between the server and browser clients need to be optimized to tackle this important concern for all. And let’s look into how to optimize the performance of the webserver using compression and caching methods.

APACHE
Apache achieves this by gziping the web contents before transfer using deflate module and by enabling caching of static files at client browsers for a particular period.

To compress,

Start with the following command to load deflate module to apache with apxs utility;

apxs-c -i-a mod_deflate.c

Use the following command to load header module;

apxs -c -i -a mod_headers.c

You can now restart apache. For listing out the loaded modules, use the following commands

httpd -M
deflate_module (shared)
headers_module (shared)

You should get these two modules.

Once you have the above modules, add the following configuration inside the virtual hosting parameter.

<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bOpera !no-gzip
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip)$ no-gzip dont-vary
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>

To Cache…

Caching is the next step in the optimization process. Enter the following command to Load expires module,

apxs -c -i -a mod_expires.c
then Load header module using the command below,
apxs -c -i -a mod_headers.c
restart apache, ensure that you find the new modules
httpd -M
expires_module (shared)
headers_module (shared)
Now, we can add the following configuration inside the virtual hosting parameter.

<IfModulemod_expires.c>

   ExpiresActiveOn

    ExpiresDefault “access plus 1 seconds”

    ExpiresByType image/x-icon “access plus 2692000 seconds”

    ExpiresByType image/jpeg”access plus 2692000 seconds”

    ExpiresByType image/png “access plus 2692000 seconds”

    ExpiresByType image/gif”access plus 2692000 seconds”

    ExpiresByType application/x-shockwave-flash “access plus 2692000 seconds”

    ExpiresByType text/css “access plus 2692000 seconds”

    ExpiresByType text/javascript “access plus 2692000 seconds”

    ExpiresByType application/x-javascript “access plus 2692000 seconds”

    ExpiresByType text/html “access plus 600 seconds”

    ExpiresByType application/xhtml+xml “access plus 600 seconds”

</IfModule>

<IfModulemod_headers.c>

    <FilesMatch”\\.(ico|jpe?g|png|gif|swf|css|js)$”>

        Header set Cache-Control “max-age=2692000, public”

    </FilesMatch>

    <FilesMatch”\\.(x?html?|php)$”>

        Header set Cache-Control “max-age=600, private, must-revalidate”

    </FilesMatch>

    Header unset ETag

    Header unset Last-Modified

</IfModule>

We can give the caching duration as seconds, week, month as shown in the configuration above.
The `must-revalidate`  that we are passing through headers, validates for any changes rather than blind caching of files.

NGINX
For compressing use the below configuration,
gzip on;
gzip_http_version 1.0;
gzip_comp_level 6;
gzip_min_length 0;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types text/plain application/x-javascript application/javascript text/css text/xml text/javascript application/xml application/xml+rss application/json;
gzip_disable “MSIE [1-6]\.”;
gzip_vary on;

For caching use the below sample configuration,
location ~ .(css|js)$ {
expires 604800s;
add_header Pragma .public.;
add_header Cache-Control .public,must-revalidate,proxy-revalidate.;
}
location ~ .(txt|xml)$ {
expires 3600s;
add_header Pragma .public.;
add_header Cache-Control .public,must-revalidate,proxy-revalidate.;
}
location ~ .(bmp|gif|ico|jpg|JPG|jpeg|jpe|swf|tif|tiff|png)$ {
expires 2592000s;
add_header Pragma .public.;
add_header Cache-Control .public,must-revalidate,proxy-revalidate.;
}

As of my experience for compression and caching, nginx is more better than apache.
So if you are using apache, it would be better if you use nginx as a reverse proxy in front of it.