2. Gaurav Mishra <gmishx@gmail.com>
Apache http server
• One of the most commonly used open source sever
• Can be easily tuned
• Works in harmony with PHP
• Provides various security measures
• Installs as httpd in many Linux distros
• Packages as apache2 in Debian based distributions
2/27/2018
3. Gaurav Mishra <gmishx@gmail.com>
Apache directory structure
• The apache foundation have their hierarchical structure for the respective
configuration files.
• The root is located at: /etc/apache2/
• The main configuration file is located at ./apache2.conf
• The modules currently installed are located at: ./mods-available/
• The modules currently in use are located at: ./mods-enabled/
• The websites/virtual host available for current install are located at: ./sites-available/
• The websites/virtual host being used for current run are located at: ./sites-enabled/
2/27/2018
4. Gaurav Mishra <gmishx@gmail.com>
Apache configuration file
• The global configuration file is stored at /etc/apache2/apache2.conf
• Can be overridden for each directory using .htaccess
• The file contains directives, mostly distributed in directive blocks
• Commonly used directive blocks:
▫ directory
Contains directives defined for a particular directory
▫ VirtualHost
Directives defined for a virtual host
2/27/2018
6. Gaurav Mishra <gmishx@gmail.com>
Setting up directory directive
Alias “/holidaypics” “/var/www/html/newpics”
<Directory /var/www/html/newpics>
AuthType Basic
AuthName Newpics
AuthUserFile /web/users
AuthGroupFile /web/groups
<IfModule mod_dir.c>
DirectoryIndex index.php
</IfModule>
<Files dinner.jpg>
order deny,allow
deny from all
allow from 127.0.0.1
</Files>
</Directory>
2/27/2018
7. Gaurav Mishra <gmishx@gmail.com>
Setting up VirtualHost
• Virtual hosting allows the Apache web server to host multiple websites as part of its
own.
ServerName server.example.com
ServerAlias server server2.example.com server2
ServerAlias *.example.com
<VirtualHost server.example.com:80>
Alias /files /home/user/Documents/files
<Directory "/home/user/Documents/files">
AllowOverride None
Options FollowSymLinks MultiViews
</Directory>
</VirtualHost>
2/27/2018
8. Gaurav Mishra <gmishx@gmail.com>
Setting up SSL support
<IfModule mod_ssl.c>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/certi.cer
SSLCertificateKeyFile /etc/ssl/keys/certi.key
</VirtualHost>
</IfModule>
2/27/2018
9. Gaurav Mishra <gmishx@gmail.com>
Apache tools
• To enable a website configuration from /etc/apache2/sites-available/mysite.conf
▫ a2ensite mysite
• To disable a website configuration from /etc/apache2/sites-available/mysite.conf
▫ a2dissite mysite
• To enable a module from /etc/apache2/mods-available/mymod.conf
▫ a2enmod mymod
• To disable a module from /etc/apache2/mods-available/mymod.conf
▫ a2dismod mymod
• Check the syntax of apache2.conf
▫ apachectl configtest
2/27/2018
10. Gaurav Mishra <gmishx@gmail.com>
Cron jobs
• Cron jobs are set of actions which must be executed at a certain time on a given day.
• Cron daemon keeps checking these cron jobs and execute them whenever required.
• Each user can have their own cron jobs.
• The job set by a user run with their privileges.
• The cron jobs are stored in crontab files.
2/27/2018
11. Gaurav Mishra <gmishx@gmail.com>
Crontab format
• The format of a crontab field follows:
▫ minute hour day-month month day(s)-week task
• A crontab entry has six fields:
▫ The first five are used to specify the time for an action
The first field specifies the minute (0–59)
The second field specifies the houst (0-23)
The third field specifies the day of the month (1–31)
The fourth field specifies the month of the year (1–12, or month prefixes like Jan and Sep)
And the fifth field specifies the day of the week (0–6, or day prefixes like Wed and Fri),
starting with 0 as Sunday.
▫ The last field is the action itself.
• Each field can be defined as range or using * to match all
2/27/2018
12. Gaurav Mishra <gmishx@gmail.com>
Crontab examples
• Take backup at 2:00 AM from Mon-Friday of every month
▫ 0 2 * * 1-5 tar cf /home/backp /home/projects
• Take backup at 2:00 AM on Sun, Wed, Fri of every month
▫ 0 2 * * 0,3,5 tar cf /home/backp /home/projects
• Take backup every other day at 2:00 AM on any day
▫ 0 2 */2 * * tar cf /home/backp /home/projects
2/27/2018
13. Gaurav Mishra <gmishx@gmail.com>
Adding a cron job
To add a cron job
1. First write the job in the respective 6 columns in a file.
▫ echo “0 2 * * 1-5 tar cf /home/backp /home/projects” > mybackup_script
2. Pass the file to crontab
▫ crontab mybackup_script
To edit a job already added
1. Open the crontab in edit mode
▫ crontab -e
2. Edit the job
3. Save the changes
Check all the jobs for current user
• crontab -l
2/27/2018
15. Gaurav Mishra <gmishx@gmail.com>
Proxy servers
• Proxy servers acts as an intermediate
between the client and the server.
• They serve many purpose.
• Caching
• Anonymizing
• Load management
• Redirection
• Every client sends a request to the
proxy, the proxy checks if it can serve
the request from it’s cache otherwise
forward it.
• Proxy sometimes helps working with
firewalls.
2/27/2018
16. Gaurav Mishra <gmishx@gmail.com>
Setting up proxy on host
• Majority of the software support proxy
• The most common place to find the proxy setting is in the System environment
variable http_proxy, https_proxy, ftp_proxy.
• The variables can be set using the export command a given terminal session.
• They can also be set using the /etc/profile and /etc/bash.bashrc files for sessions
globally.
• The string follows following pattern:
▫ [username]:[password]@ipaddress:port
▫ http://[username]:[password]@address.com:port
2/27/2018