Linux Administration

How To Add New Modules In Apache

A module provides variety of features for apache such as security, perl and php support etc. To configure apache for additional modules you need to add LoadModule directive in httpd.conf or modules.conf file. For example you can add session management and tracking through consistent identifiers using mod_session. You need to add following entry to Apache 1.3.xx server (under Debian Linux you need to add to /etc/apache-perl/modules.conf file):

LoadModule auth_module /usr/lib/apache/1.3/mod_session.so

Please note that your Apache server must configure for Dynamic Shared Objects (DSOs). Let us assume you have downloaded the module called mymodule.c and you would like to compile and use this module, then you can use Apache apxs utility to compile and install this module:

Build and install a third-party Apache module, say mod_foo.c, into its own DSO mod_foo.so outside of the Apache source tree using apxs:

# apxs -c mymodule.c
# apxs -i -a -n mymodule mymodule.la

Then open your httpd.conf file and add mymodule using top LoadModule Directive:

# vi httpd.conf

Append following line to server config context (this means that the directive may be used in the server configuration files (e.g., httpd.conf), but not within any or containers. It is not allowed in .htaccess files at all).

LoadModule mymodule /usr/lib/httpd/modules/mymodule.so

Be the first to comment - What do you think?  Posted by ZACH - January 31, 2012 at 10:14 pm

Categories: Linux Administration   Tags: , ,

Speed Webpages Using Mod_Deflate Module On Apache

Mod_deflate module is used with Apache to increase the speed of download. This module can be used with Apache and it will compress the data before sending to the client. It now been installed by default with most flavours. So you can check before you try to install it. Note: Processing takes additional CPU and memory on your server as well as on the client browser.

Below example show how to enable mod_deflate module.

LoadModule deflate_module modules/mod_deflate.so

Append following configuration directive:

AddOutputFilterByType DEFLATE text/html text/plain text/xml
….

Above line only compress html and xml files. Here is the configuration from one of my production box:



AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE application/x-httpd-eruby
AddOutputFilterByType DEFLATE text/html


Close and save the file. Next restart apache web server. All of the above extension file should compressed by mod_deflate:
# /etc/init.d/httpd restart

You can also specify specific directory and enabling compression only for the html files. For example /static/help/ directory:

AddOutputFilterByType DEFLATE text/html

In real life, there are issues with compressing other types of files such as mp3 or images. If you don’t want to compress images or mp3 files, add following to your configuration:
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-vary

Be the first to comment - What do you think?  Posted by ZACH - December 14, 2011 at 10:05 am

Categories: Linux Administration   Tags:

How To Disable Apache Directory Listing

In your httpd.conf file you should have something like this:


Options Indexes FollowSymLinks
bla bla bla

To disable directory listing for that directory REMOVE the ‘Indexes’
option. Also, you can use ‘-Indexes’ for that and, sure, you can make a
new entry for a specific directory

OR

One of the “must do’s” on setting a secure apache webserver environment is to disable directory browsing. As a default Apache will be compiled with this option enabled, but its always a good idea to get rid of this setting unless its really necessary. If you have some basic knowledge of vi editor follow this steps

If you are on an RPM installation of Apache (which i dont really recommend) you will find the apache configuration file probably here:

/etc/httpd/conf/httpd.conf

If you are using apache from the source tar balls ( like real men ) probably you will find the configuration file here:

/usr/local/apache/conf/httpd.conf

Using an editor like vi , edit the httpd.conf file and scroll until you find a line like this:

Options All Indexes FollowSymLinks MultiViews

To disable directory browsing carefully remove the line that says: Indexes and leave the line like this:

Options All FollowSymLinks MultiViews

Restart your apache webserver and thats all.

Be the first to comment - What do you think?  Posted by ZACH - December 2, 2011 at 4:19 pm

Categories: Linux Administration   Tags: ,

Sample Apache Virtual Host Entry

A sample Apache Virtual Host Entry for your reference.

vi /etc/httpd/conf/httpd.conf

————————
————————-
——————————
NameVirtualHost 67.159.54.145:80
NameVirtualHost 67.159.54.146:80


ServerName sample.com
ServerAlias www.sample.com
DocumentRoot /home/sample/public_html


ServerName techside.com
ServerAlias www.techside.com
DocumentRoot /home/techside/public_html

=============================================================
hash all lines in this file other wise default page will display

/etc/httpd/conf.d/welcome.conf

#
# This configuration file enables the default “Welcome”
# page if there is no default index page present for
# the root URL. To disable the Welcome page, comment
# out all the lines below.
#
#
# Options -Indexes
# ErrorDocument 403 /error/noindex.html
#

Be the first to comment - What do you think?  Posted by ZACH - November 30, 2011 at 3:24 pm

Categories: Linux Administration   Tags:

Basic authentication of HTTP users using htpasswd command

htpasswd is used to create and update the flat-files used to store usernames and password for basic authentication of HTTP users. If htpasswd cannot access a file, such as not being able to write to the output file or not being able to read the file in order to update it, it returns an error status and makes no changes.

Create a new password file

Following command will creates a new file and stores a record in it for user jerry. The user is prompted for the password. If the file exists and cannot be read, or cannot be written, it is not altered and htpasswd will display a message and return an error status.

# htpasswd -c /home/pwww/.htpasswd user

Change or update password

To add or modifies the password for user tom, enter:

# htpasswd /home/pwww/.htpasswd-users tom

The user is prompted for the password.

Be the first to comment - What do you think?  Posted by jomos - November 24, 2011 at 10:29 am

Categories: Linux Administration   Tags: ,