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
Click Like To Learn Linux
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.
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
#
Apache generates semaphores and when it can not generate more, you should get an error like this:
“No space left on device:mod_rewrite: could not create_rewrite: could not create rewrite_log_lockConfiguration Failed”
You should delete semaphores to fix it.
Listing and deleting semaphores :
# ipcs -s grep apache
# ipcs -s grep apache perl -e ‘while () { @a=split(/\s+/); print `ipcrm sem $a[1]`}’
You should be able to start apache fine now.
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.