Академический Документы
Профессиональный Документы
Культура Документы
9325B
1:00-2:30 W.S.
II. Apache2
A. Installation...............................................................................................2
B. Preparation..............................................................................................2
References...........................................................................................................................14
I. Introduction
B. Requirements
1. Oracle VM VirtualBox v.5.2.0
2. Oracle VM VirtualBox Extension Pack v.5.2.0
3. Ubuntu Server 16.04
4. An internet connection
C. Download links
1. Oracle VM VirtualBox: https://www.virtualbox.org/wiki/Downloads
2. Oracle VM VirtualBox Extension Pack
https://www.virtualbox.org/wiki/Downloads
3. Ubuntu Server: https://www.ubuntu.com/download/server
1
II. Apache2
A. Installation
1. First, we update by typing “sudo apt-get update”
2. After the update typee “sudo apt-get install apache2”
B. Preparation
2
III. Virtual Hosts
A. Setup
1. Check first the status of apache by typing “sudo service apache2 status”
2. Make sure the apache server is running.
3. Clone your repository to the root folder of the server (if you want to use
your website)
8. Save the html file by pressing esc key and typing “:wq” then hit enter
9. Go to the root directory by typing “cd”
10. Go to “cd /etc/apache2/sites-available/”
11. We want to copy the default configuration by
“cp sudo cp 000-default.conf group6.com.conf”
14. Save the file by pressing esc key and typing “:wq” then hit enter
15. After saving we first check the hostname by typing “hostname -I”
16. Then we locate our hosts file (from the host machine) and open it
in Windows go to C:\Windows\System\Drivers\etc
3
17. We add the hostname and the website we created
19. We go back to the server and enable the configuration we just created
20. Then we disable the default configuration by “sudo a2dissite 000- default.conf”
21. Then we type “service apache2 reload” and hit enter
22. Now go to the host machine and access the website created
B. Compression
1. Change directory to the directory of the website created “cd
/var/www/group6.com”
4
C. Cache (for jpg,gif,png files)
1. Enable the cache module by typing “sudo a2enmod cache”.
2. Enable the expires module by typing “sudo a2enmod expires”.
3. Restart apache by “service apache2 restart”
4. Go to your root directory
5. Change directory by “cd /etc/apache2/sites-available”
6. Then we edit our site configuration by “sudo vi group6.com.conf”
7. Press “i” to insert the following text (inside the VirtualHost tag)
<Location />
CacheEnable disk
ExpiresActive on
ExpiresByType image/gif “access 24 hours”
ExpiresByType image/jpg “access 24 hours”
ExpiresByType image/png “access 24 hours”
</Location>
8. Save the file by pressing esc key and typing “:wq” then hit enter.
9. We open our website and inspect to check if the content is cached, first we go the
Networks tab then click the html file and headers tab.
10. We check the “Cache-control” header to check, once successful it will display the
duration the content will be cached.
5
D. Content Negotiation
1. Navigate to the html folder by typing “cd /var/www”
This is where a folder where the files we will be using to demonstrate Apache negotiation
will be saved.
2. Now, to create that folder, type “sudo mkdir webtech1.negotiate.org”, then hit enter.
Entering your password may be required.
-------------------------------------------------------------------------------------------------------------------
HTTP ACCEPT HEADER
4. So, what we are going to do now, is to create two dummy files to be used for
demonstrating Apache HTTP Accept Header. In this demonstration, we will be creating the
files: content.html and content.txt
4.1. To do so, type “sudo vi content.html”
5. Now, we are to change the directory where we will be creating configuration file for our
virtual host, webtech1.negotiate.org. To do so, enter the following: “cd /etc/apache2/sites-
available/”.
6
6. We are now to create the configuration file for webtech1.negotiate.org. The fastest way to
do so, is to copy the default configuration file, then modify it.
6.1. Let us first check the files available in the directory, to make sure that we
will be copying the right file. To view the list of files, enter “ls”.
6.2. Now, we are going to copy the default configuration file, 000-default.conf
and then name its copy with webtech1.negotiate.org. To do so, enter the
following:
“sudo cp 000-default.conf webtech1.negotiate.org.conf”
6.4. We
are now ready to modify webtech1.negotiate.org.conf, to enable the clients to
negotiate with the servers, using HTTP Accept header.
6.4.1 In order to modify it, we first have to open the file through the vi. To
do so, enter:
“sudo vi webtech1.access.org.conf”
6.4.4 To save and close the file, press the esc key and type “:wq” or “:x”,
then hit enter.
7
HTTP ACCEPT-LANGUAGE HEADER
7. Now we have to create two dummy files, language.html.en and language.html.fil to be used for
Apache HTTP Accept-Language Header demonstration. But first, we will have to navigate
to the document roots of our virtual hosts, where the dummy files will be placed on.
7.2. And now we are ready to create the dummy files. To do so, type “sudo vi
language.html.en”
7.3. Add some text to the file, by pressing i to enable insert mode. Then press on the
esc key and type “:wq” or “:x” to save and close the file. Same process as #4.
7.4. Now, for the 2nd dummy file, language.html.fil, follow the same steps done from
#7.1 to #7.3, except that the name of the file must be changed.
8. After creating the files, we are now going to configure the virtual host to negotiate with
the server using the Apache HTTP Accept-Language header.
8.3. To be able to do some modifications to the file, press i. Then add the following inside
the <Directory> section.
Add Language en .en
Add Language fil .fil
8.4. Save and exit, as usual. Press the esc key and type “:wq” or “:q”then hit enter.
-------------------------------------------------------------------------------------------------------------------
9. Now, we are to enable the webtech1.negotiation.org.conf. To do so, just enter “sudo a2ensite
webtech1.negotiation.org.conf”
10. For the changes to take place, restarting the service is required. Just enter “sudo service
apache2 restart”
8
11. And since we have already enabled our target configuration, let us disable the default
configuration. You may do this first before enabling the target configuration.
13.2 From the host machine, let us locate our hosts file.
If you are using Windows, go to C:\Windows\System32\drivers\etc
13.3 Open the hosts file, then add the following:
ip address<space>site name (www.<siteName>.org),
14. Access the website through a chosen browser on your host machine.
E. Site Access
1. Check first the status of apache by typing “sudo service apache2 status”
2. Make sure the apache server is running.
3. Navigate to the html folder by typing “cd /var/www”
4. Create a folder for your website “sudo mkdir webtech1.access.org”
5. Go to the created folder by “cd /var/www/webtech1.access.org”
6. Create an html file by “sudo vi index.html”
7. Save the html file by pressing esc key and typing “:wq” then hit enter
8. Go to “cd /etc/apache2/sites-available/”
9. We want to copy the default configuration by “ sudo cp 000-default.conf
webtech1.access.org.conf”
10. Then we modify the configuration by “sudo vi webtech1.access.org.conf”
9
11. We change the default ServerName to “www.webtech.access.org”, ServerAlias to
“webtech1.access.org” in addition to ServerAlias “webtech.access.edu”, and
DocumentRoot to “/var/www/webtech1.access.org”.
12. Input the following commands to enable only GET, HEAD, and POST requests
and have the POST request be allowed to authenticated users.
13. Save the file by pressing esc key and typing “:wq” then hit enter
14. After saving we first check the hostname by typing “hostname -I”
15. We then create folders to store our password along with the users, for this use “sudo
htpasswd -c /var/www/access .htpasswd user1”. If there are multiple users repeat
the previous command but just remove the “-c” flag since its purpose is for the
creation of the file.
16. Then we locate our hosts file (from the host machine) and open it
F. SSI
1. Check first the status of apache by typing “sudo service apache2 status”
2. Make sure the apache server is running.
3. Navigate to the html folder by typing “cd /var/www”
4. Create a folder for your website “sudo mkdir webtech1.ssi.org”
5. Go to the created folder by “cd /var/www/webtech1.ssi.org”
6. Create an html file by “sudo vi index.html”
10
7. Create an htaccess file by typing “sudo vi .htaccess”, input the ff:
<Directory “/var/www/xbithack”>
Options +Includes
XBitHack on
</Directory>
<Directory “/var/www/extension”>
Options +includes
AddType text/html .html
AddOutPutFilter INCUDES .html
</Directory>
The former is for activating XBitHack directive while the latter is the filename
extension based approach.
8. Save the html file by pressing esc key and typing “:wq” then hit enter
9. Go to the root directory by typing “cd”
10. Go to “cd /etc/apache2/sites-available/”
11. We want to copy the default configuration by “sudo cp 000-default.conf
webtech1.ssi.org.conf”
12. Then we modify the configuration by “sudo vi webtech1.ssi.org.conf”
13. We change the default ServerName to “webtech.ssi.org”, ServerAlias to
“webtech1.ssi.org”, and DocumentRoot to
“/var/www/webtech1.ssi.org/public_html”.
14. Save the file by pressing esc key and typing “:wq” then hit enter
15. After saving, create a folder named extension by in “/var/www”
The header.html and footer.html are SSIs is not naturally part of the original HTML
file.
18. After saving, create a folder named extension by in “/var/www”
11
21. After that we first check the hostname by typing “hostname -I”
22. Then we locate our hosts file (from the host machine) and open it
G. SSL
1. Check first the status of apache by typing “sudo service apache2 status”
2. Make sure the apache server is running.
3. Navigate to the html folder by typing “cd /var/www”
4. Create a folder for your website “sudo mkdir webtech1.secure.org”
5. Go to the created folder by “cd /var/www/webtech1.secure.org”
6. Create an html file by “sudo vi index.html”
7. Save the html file by pressing esc key and typing “:wq” then hit enter
8. Go to the root directory by typing “cd”
9. Go to “cd /etc/apache2/sites-available/”
10. We want to copy the default configuration by “sudo cp 000-default.conf
webtech1.secure.org.conf”
11. Then we modify the configuration by “sudo vi webtech1.secure.org.conf”
We change the default ServerName to “webtech.secure.org”, ServerAlias to
“webtech1.secure.org”, DocumentRoot to “/var/www/webtech1.secure.org/”, and
add Redirect permanent / https://webtek.secure.org/
12. Save the file by pressing esc key and typing “:wq” then hit enter
13. Input the following command “sudo openssl req -x509 -nodes -days 365 -newkey
rsa:2048 –keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-
selfsigned.crt ”
14. Go to “cd /etc/apache2/sites-available/”
15. Copy the default ssl configuration into a new one by “sudo cp default-ssl.conf
webtech1.secure.org-ssl.conf”
16. Edit the new ssl configuration by “sudo vi webtech1.secure.org-ssl.conf”
17. Add or change the following
12
18. After that we first check the hostname by typing “hostname -I”
19. Then we locate our hosts file (from the host machine) and open it
13
References
1&1. (2018). Configure HTTP Content Caching in Apache on Ubuntu 16.04. [online]
Available at: https://www.1and1.com/cloud-community/learn/web-
server/apache/configure-http-content-caching-in-apache-on-ubuntu-1604/ [Accessed 25
Feb. 2018].
14