Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts

Saturday, January 06, 2007

Apache Performance Tips - Part 1

A few basic tips will go a long way in enhancing your Apache performance. You will have to put in the directives in your httpd.conf or the through a seperate .conf file which you can include through the httpd.conf file.

1. Cache those frequent pages!

How often do you see the Home Page being very slow to load up? A tip would be to use a caching module to cache those pages you think will be loaded very frequently. These pages will be loaded in the memory instead of being retrieved from the filesystem everytime.

Module to use:

mod_file_cache

How and What to use:

There are 2 directives that you can use MMapFile and CacheFile which you can use to Cache the pages you want.

Read the differences between MMapfile and CacheFile

For Example:

CacheFile /home/web2/index.htm
CacheFile /home/web2/about.htm

The above two directives will cache index.htm and about.htm


Don't forget to read the above module page to find out how to cache the contents of a entire directory ;-)

2. Don't use DNS lookups

You don't use the HostNameLookups directive to lookup for dns names in your log file - This is disabled by default in Apache 1.3 and above versions.

Also, make sure you always use a IP address instead of a domain names in your Allow or Deny directives either. It will cost you a lot of performance.

If you need hostnames in your logfile, you just use logresolve

How to use:

HostNameLookUps Off

3. Keep your site alive

HTTP works by requesting for a document over a new connection. So, everytime you request a document, a new socket connection is established, once served, the connection is closed. The time spent for establishing a connection and closing it can be avoided using a directive called KeepAlive

How to use:

KeepAlive On

Other Related Directives

With the above KeepAlive directive, there are 2 other related directives - MaxKeepAliveRequests and KeepAliveTimeout.

MaxKeepAliveRequests is the number of requests to be allowed over a single connection. Default value for MaxKeepAliveRequests is 100. If you have a lot of memory to spare, you could consider putting MaxKeepAliveRequests to 0 to allow unlimited number of connections

KeepAliveTimeout is used to timeout the connection - you don't want to keep the connection established with the client even though they are not using your site - do you ? 15-20 seconds should be a ideal value for KeepAliveTimeout

How to use:

MaxKeepAliveRequests 100
KeepAliveTimeout 20

4. Consider mod_perl

If you are using CGI perl based web application, it pays to consider to using mod_perl

Read this excellent article on mod_perl

How to do it:

PerlModule ModPerl::PerlRun Alias /cgi-bin/ /opt/apache2/cgi-bin/
<location >
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
Options +ExecCGI
< /location >

or

PerlModule ModPerl::Registry
Alias /cgi-bin/ /opt/apache2/cgi-bin/
<location >
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
Options +ExecCGI
< /location >
As you see, there are 2 ways to go about using mod_perl, one is the PerlRun method and other is the Registry method basic difference being that in Registry method, code is cached after compilation whereas it isn't . Read more about the porting guidelines

5. Share the load

If you have 2 or more webservers - you can share the load amongst them by shifting some of the pages to the other webserver.

Module to use:

mod_proxy

How and What to use:

ProxyPass /images/ http://web2.techflock.com/
ProxyPassReverse /images/ http://web2.techflock.com/

Read about the above directives at Apache documentation

...to be continued ..

Meanwhile you can also go through Apache Tuning

Wednesday, January 03, 2007

apxs - APache eXtenSion tool

apxs is a apache tool which lets you build and install apache extensions. All the modules built using apxs are loaded dynamically at runtime using the LoadModule directive

To know more about apxs - head to the Apache site

Mask your Site

We present to you a few feature as well as security enhancements to mask your webserver and site from web attacks!

  • Do not use a default extension even though you use a language like php or aspx. If you can make it go away in entirety - the better! And do use Clean URLs Search engines love Clean URLs
  • Modify your header information so that it returns something not so obvious. Take a look at mod_headers module
  • Do not use CGI or SSI (Server Side Includes) - both of them are heavy on the server and vulnerable to attacks
  • If you have a popular site, you might want to consider using something like Modsecurity which is a web application firewall which allows real time monitoring and analysis
  • Get a book - Apache Security is a good start

Thursday, November 23, 2006

Putting favicon on your Apache

Put a favicon.ico (icon file) into the desired directory /images/favicon.ico under ServerRoot

AddType image/x-icon .ico
<Files favicon.ico>
ErrorDocument 404 /images/favicon.ico
</Files>

favicon should be 16x16 image

Friday, November 17, 2006

Apache Tip - cgi-bin for every user

You want to give cgi-bin access to all the users on your webserver.

Add the following directive entries in your httpd conf file


<Directory /home/*/public_html/cgi-bin/>
Options ExecCGI
SetHandler cgi-script
</Directory>

Saturday, October 21, 2006

Apache Tip - Case Insensitive URLs

Making Apache recognize case-insensitive urls is rather easy.

Load up the mod_speling module (yep, speling)

And, use the directive

CheckSpelling On

For more on the mod_speling module - check the Apache manual