Previous |
Home | Next |
Version: | - httpd 2.2.0 |
- squirrelmail 1.4.6 |
Configuration
File Dir: |
/etc/httpd/conf |
Extra
Module Files Dir: |
/etc/httpd/conf.d |
[bash]# cp
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/httpd.conf.original [bash]# vi /etc/httpd/conf/httpd.conf |
ServerRoot "/etc/httpd" |
DO
NOT add a trailing
slash "/" to the directory names when making changes. If they are
already there (like cgi-bin), then leave them. |
Listen 80 | All
clients can connect (preferred) |
Listen
192.168.1.1:80 |
Only
clients on the internal network
can connect |
LoadModule
userdir_module modules/mod_userdir.so LoadModule cgi_module modules/mod_cgi.so LoadModule rewrite_module modules/mod_rewrite.so |
Include conf.d/*.conf |
ExtendedStatus On |
User apache Group apache |
ServerAdmin
[email protected] |
ServerName www.example.com:80 |
UseCanonicalName On |
For DNS, the servers
real name is galaxy,
the www
name is an alias (CNAME)
which points to the real galaxy
hostname. |
DocumentRoot "/var/www/html" |
DirectoryIndex
index.html index.html.var |
AccessFileName .htaccess |
It is widely known that
Apache uses the filename ".htaccess"
as the
default file for basic authentication. It is recommended
that you change the name of the file as any serious attacker will
definitely target that filename. The file should be safe, but the extra
precaution won't hurt. Keep with ".ht" for start of filename. |
HostnameLookups Off |
ServerSignature Email |
AddDefaultCharset UTF-8 |
<Location
/server-status> SetHandler server-status Order deny,allow Deny from all Allow from .example.com Allow from 127.0.0.1 192.168.1.0/24 </Location> |
<Location
/server-info> SetHandler server-info Order deny,allow Deny from all Allow from .example.com Allow from 127.0.0.1 192.168.1.0/24 </Location> |
[bash]# chkconfig
--level 345 httpd on [bash]# chkconfig --list httpd |
[bash]# /etc/init.d/httpd
restart [bash]# grep httpd /var/log/messages [bash]# tail /var/log/httpd/error_log |
[bash]# yum install netpbm-progs |
[bash]# vi /bin/makefavicon |
#!/bin/sh if [ -z $1 ] ; then echo -e "\\nUsage: \"makefavicon <image_filename.png>\"\\n" echo -e "Suitable file types are: PAM, PNM, PPM, PGM, or PBM.\\n" exit fi rm -f favicon.ico pamscale -linear -xsize=48 -ysize=48 $1 > tmp_logo48.ppm pamscale -linear -xsize=32 -ysize=32 $1 > tmp_logo32.ppm pamscale -linear -xsize=16 -ysize=16 $1 > tmp_logo16.ppm pnmquant 256 tmp_logo48.ppm > tmp_logo48x48.ppm pnmquant 256 tmp_logo32.ppm > tmp_logo32x32.ppm pnmquant 256 tmp_logo16.ppm > tmp_logo16x16.ppm ppmtowinicon tmp_logo16x16.ppm tmp_logo32x32.ppm tmp_logo48x48.ppm -output favicon.ico rm -f tmp_logo*.ppm |
[bash]# chmod +x /bin/makefavicon |
[bash]# makefavicon image_file.ppm |
[bash]# pngtopnm -mix pic_file.png > file_to_convert.pnm [bash]# makefavicon file_to_convert.pnm |
[bash]# cp favicon.ico /var/www/html/ |
[bash]# vi /var/www/html/index.html |
<link rel="icon" href="favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"> |
Username |
Home
Directory |
Users
URL |
alice |
/home/alice/public_html | http://www.example.com/~alice |
bob |
/home/bob/public_html | http://www.example.com/~bob |
[bash]# vi /etc/httpd/conf/httpd.conf |
<IfModule
mod_userdir.c> # UserDir disable UserDir public_html </IfModule> |
<Directory
/home/*/public_html> AllowOverride FileInfo AuthConfig Limit Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory> |
Permissions |
Resource |
chmod
701 |
/home/* |
chmod 705 | /home/*/public_html |
chmod 604 | /home/*/public_html/*.html |
chmod 705 | /home/*/public_html/cgi-bin |
chmod 705 | /home/*/public_html/cgi-bin/*.cgi
(or *.pl) |
[bash]# mkdir
/etc/skel/public_html [bash]# mkdir /etc/skel/public_html/cgi-bin [bash]# chmod 705 /etc/skel/public_html [bash]# chmod 705 /etc/skel/public_html/cgi-bin/ |
Not all Linux
distributions have the skeleton profile located
in the same area. |
[bash]# echo 'Test User
Page !' >
/etc/skel/public_html/index.html [bash]# chmod 604 /etc/skel/public_html/index.html |
[bash]# vi
/etc/skel/public_html/cgi-bin/test.cgi |
#!/usr/bin/perl |
[bash]#
chmod 705
/etc/skel/public_html/cgi-bin/test.cgi |
Setting cgi-bin
files, directories and permissions in the skeleton profile DOES NOT
enable CGI for local users, this must be configured manually in the httpd.conf
file before the
service is available. |
### SELinux ONLY - Enable User Website [bash]# setsebool -P httpd_enable_homedirs true [bash]# chcon -v -R -h -u user_u -t httpd_user_content_t /home/*/public_html |
### SELinux ONLY - Disable User Website [bash]# setsebool -P httpd_enable_homedirs false [bash]# chcon -v -R -h -u user_u -t user_home_t /home/*/public_html |
[bash]# vi /etc/httpd/conf/httpd.conf |
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" |
<Directory
"/var/www/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory> |
<Directory
/home/*/public_html/cgi-bin> Options ExecCGI SetHandler cgi-script </Directory> |
AddHandler cgi-script
.cgi .pl
|
It is important to note that the authorisation files are not located inside the "DocumentRoot" structure, otherwise they could be downloaded if not properly secured. |
# Provides security for
"http://www.example.com/private" <Directory "/var/www/html/private">
AuthType Basic AuthName "Private
Area -
Authorisation Required" AuthUserFile /etc/httpd/conf/authusers AuthGroupFile /etc/httpd/conf/authgroups
Require group private #
Require valid-user Options Indexes FollowSymLinks AllowOverride None </Directory> |
[bash]# vi
/etc/httpd/conf/authgroups |
private: alice bob jane friends: mark linda andrew superusers: linda bob |
[bash]# touch
/etc/httpd/conf/authusers [bash]# htpasswd
/etc/httpd/conf/authusers
alice
|
You should always use
the touch
command to create a
username/password file, using the wrong command line option (-c)
will overwrite an existing
file. |
[bash]$ vi .htaccess
|
AuthType
Basic AuthName
"Alice's Private Area" AuthUserFile .htauthusers
Require
valid-user |
[bash]$
touch .htauthusers[bash]$ htpasswd .htauthusers alice
|
AllowOverride AuthConfig |
You should be aware
there is a possibility that usernames and
passwords are able to be intercepted during authentication by
malicious users. This can be secured by using encryption techniques
like SSL and TLS. |
[bash]# vi /etc/httpd/conf/httpd.conf |
NameVirtualHost *:80 #Virtual Host 1 - EXAMPLE.ORG <VirtualHost *:80> ServerName www.example.org ServerAdmin [email protected] DocumentRoot /var/webhosts/www.example.org CustomLog logs/www.example.org-access_log common ErrorLog logs/www.example.org-error_log </VirtualHost> #Virtual Host 2 - EXAMPLE.NET <VirtualHost *:80> ServerName www.example.net ServerAdmin [email protected] DocumentRoot /var/webhosts/www.example.net CustomLog logs/www.example.net-access_log common ErrorLog logs/www.example.net-error_log </VirtualHost> |
Configuration
File: |
/etc/httpd/conf.d/ssl.conf |
[bash]# mkdir
/root/SSL_Certs [bash]# chmod 600 /root/SSL_Certs [bash]# cd /root/SSL_Certs |
[bash]# openssl req -newkey rsa:1024 -keyout private.key -out certsignreq.csr |
Generating a 1024 bit RSA private key .....++++++ .++++++ writing new private key to 'private.key' Enter PEM pass phrase: ENTER PASSPHRASE HERE Verifying - Enter PEM pass phrase: ENTER PASSPHRASE HERE ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [GB]:AU State or Province Name (full name) [Berkshire]:QLD Locality Name (eg, city) [Newbury]:Brisbane Organization Name (eg, company) [My Company Ltd]:Miles Brennan Organizational Unit Name (eg, section) []:Home Linux Server Common Name (eg, your name or your server's hostname) []:www.example.com Email Address []:[email protected] Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:secretword An optional company name []: |
The servers name inside
the certificate should be the fully
qualified
hostname that a user is connecting to, otherwise the web browser will
throw the user a warning message. If the servers name is
galaxy.example.com but has an alias to www.example.com which is used
for people to connect, then the certificate should have the name of
www.example.com. |
[bash]# openssl rsa -in private.key -out signingkey.key [bash]# openssl x509 -in certsignreq.csr -out selfsigned_digicert.crt -req -signkey signingkey.key -days 1825 |
[bash]# mv private.key private.key.withpassphrase [bash]# openssl rsa -in private.key.withpassphrase -out private.key [bash]# chmod 0400 private.key |
[bash]# cp private.key /etc/pki/tls/private/localhost.key [bash]# cp selfsigned_digicert.crt /etc/pki/tls/certs/localhost.crt |
[bash]# cp CAsigned_digicert.crt /etc/httpd/conf/ssl.crt/server.crt |
[bash]# vi /etc/httpd/conf.d/mod-rewrite.conf |
# Rewrite Rules. RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/webmail/(.*) https://%{SERVER_NAME}/webmail/$1 [R,L] #Debug Rewrite Rules #RewriteLog /var/log/httpd/rewrite_engine_log #RewriteLogLevel 3 |
The SSL protocol does
have some CPU overheads, so only use
it where its most practical. Don't force it for the whole server unless
you are providing a particular service to customers. |
Configuration
File: |
/etc/httpd/conf.d/squirrelmail.conf |
Alias
/webmail /usr/share/squirrelmail |
[bash]# cp
/etc/squirrelmail/config.php /etc/squirrelmail/config.php.original [bash]# vi /etc/squirrelmail/config.php |
$domain
= 'example.com'; $imapServerAddress = 'localhost'; $imapPort = 143; <-- plain IMAP protocol running on localhost (server) $useSendmail = true; $smtpServerAddress = 'localhost'; $smtpPort = 25; $sendmail_path = '/usr/sbin/sendmail'; $pop_before_smtp = false; $imap_server_type = 'uw'; |
[bash]# vi /etc/php.ini |
## NEEDED TO SUPPORT PHP WEBMAIL
LARGE FILE UPLOADS ## post_max_size = 50M upload_max_filesize = 50M memory_limit = 64M |
If you are accessing webmail from outside your network, use
SSL where possible. |
[bash]# vi /etc/dovecot.conf |
protocols = imap imaps pop3s protocol imap { listen = 127.0.0.1 ssl_listen = * ssl_disable = no } |
[bash]# cd /usr/share/squirrelmail/config [bash]# ./conf.pl |
Previous |
Home | Next |