Вы находитесь на странице: 1из 16

GUIDE MANUAL

FOR APACHE HTTP SERVER


SERVER CONFIGURATION

9325B
1:00-2:30 W.S.

De Ayre, Seanne Nielsen A.


Chinayog, Klint B.
Gonzaga, Dominic C.
Ragsac, John Yves B.
Mejia, Rapha Lynne L.
Tungcul, Camille S.
TABLE OF CONTENTS
I. Introduction
A. What is apache HTTP Server? ............................................................1
B. Requirements..........................................................................................1
C. Download links......................................................................................1

II. Apache2
A. Installation...............................................................................................2
B. Preparation..............................................................................................2

III. Virtual Hosts


A. Setup........................................................................................................3
B. Compression..........................................................................................4
C. Cache.......................................................................................................5
D. Content Negotiation.............................................................................6
E. Site Access..............................................................................................9
F. SSI............................................................................................................10
G. SSL...........................................................................................................12

References...........................................................................................................................14
I. Introduction

A. What is Apache HTTP server?


The Apache HTTP Server Project is an effort to develop and
maintain an open-source HTTP server for modern operating systems
including UNIX and Windows. The goal of this project is to provide a
secure, efficient and extensible server that provides HTTP services in sync
with the current HTTP standards. (https://httpd.apache.org/)

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

Due to dependency, the following modules must be enabled, in preparation


for the demonstrations below.

● Enabling deflate module (sudo a2enmod deflate)


○ Enables filter
○ Enables deflate

● Enabling cache_disk module (sudo a2enmod cache_disk)


○ Enables cache
○ Enable cache_disk

● Enabling deflate module (sudo a2enmod auth_basic)


○ Enables authn_core
○ Enables auth_basic

● Enabling cache_disk module (sudo a2enmod include)


○ Enables mime
○ Enable include

● Enabling cache_disk module (sudo a2enmod ssl)


○ Enables mime
○ Enables setenvif
○ Enable socache_shmcb
○ Enables ssl

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)

4. Navigate to the html folder by typing “cd /var/www”


5. Create a folder for your website “sudo mkdir group6.com”
6. Go to the created folder by cd /var/www/group6.com
7. Create an html file by “sudo vi index.html” then press i to insert text

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”

12. Then we modify the configuration by “sudo vi group6.com.conf”


13. We copy the modifications made below

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

18. We save the hosts file

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”

2. Create the .htaccess file by “sudo vi .htaccess”


3. Input the following text into the file created.
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/css text/html
</IfModule>
4. Save the file by pressing esc key and typing “:wq” then hit enter.
5. Then we restart our apache server by typing “service apache2 reload”
6. We open our website and inspect to check if the content is compressed, first we
go the Networks tab then click the html file and headers tab
7. We check the “Accept-Encoding” header to check, once successful it will display
gzip/deflate

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.

3. We can now change our directory to the created folder by typing


“cd /var/www/webtech1.negotiate.org”

-------------------------------------------------------------------------------------------------------------------
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”

As soon as we hit enter, we will be redirected to the vi, wherein will be


adding some text and then save and close the file.
4.2. To add text through the vi, just hit i, then start
typing anything you wish to.
4.3. To save and close the html file, press the esc key
and type “:wq” or “:x”, then hit enter.

This shows that we have successfully created a new file, “content.html”


4.4. Repeat process showed in #4.1-#4.3 to create a dummy text file,
content.txt

This shows that we have successfully created a new file, “content.txt”

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.3 To check if we have successfully copied the file and created


webtech1.negotiate.org.conf, enter “ls” again. And a list of files in that directory
will be displayed.

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.2 To be able to do some modifications to the file, press i. And then


change the the ServerName to “www.webtech.negotiate.org”,
ServerAlias to “www.webtech1.negotiate.org”, and
DocumentRoot to “/var/www/webtech1.negotiate.org”.

6.4.3 Add the following into the file


<Directory /var/www/webtech1.negotiate.org>
Options +Multiviews
</Directory>

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.1. To do so, enter “cd /var/www/webtech1.negotiate.org”

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.

This shows that we have successfully created a new file, “language.html.en”

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.

This shows that we have successfully created a new file, “language.html.fil”

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.1 The first thing to do is change our directory to /etc/apache2/sites-available, it is


where webtech1.negotiate.org.conf is located.

8.2. In order to modify webtech1.negotiate.org.conf , we first have to open the file


through the vi. To do so, enter:
“sudo vi webtech1.access.org.conf”

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.

12. Repeat #10

13. We are now to configure the hosts file.


13.1 First, we have to know the IP address we will be utilizing.
To know, enter “hostname –I” and the IP address will be displayed on the screen.

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

17. We add the hostname and the website we created

18. We save the hosts file


19. We go back to the server and enable the configuration we just created
20. Then we disable the default configuration by typing “sudo a2dissite 000-
default.conf”
21. We then enable the created configuration by typing “sudo a2ensite
webtech.access.org.conf”
22. Then we type “service apache2 restart” and hit enter
23. Now go to the host machine and access the website created

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”

16. Then create an Index.html file by typing “sudo vi Index.html”


17. Inside “Index.html” place :

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”

19. Then create an Index.html file by typing “sudo vi Index.html”


20. Inside “Index.html” place :

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

23. We add the hostname and the website we created

24. We save the hosts file


25. Then we disable the default configuration by typing “sudo a2dissite 000-
default.conf”
26. We then enable the created configuration by typing “sudo a2ensite
webtech.ssi.org.conf”
27. Then we type “service apache2 restart” and hit enter
28. Now go to the host machine and access the website created

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

As for the following, just uncomment them

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

20. We add the hostname and the website we created

21. We save the hosts file


22. Then we disable the default configuration by typing “sudo a2dissite 000-
default.conf”
23. We then enable the created configuration by typing “sudo a2ensite
webtech.secure.org.conf”
24. Then we type “service apache2 restart” and hit enter
25. Now go to the host machine and access the website created

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].

Httpd.apache.org. (2018). Apache httpd Tutorial: Introduction to Server Side Includes -


Apache HTTP Server Version 2.4. [online] Available at:
https://httpd.apache.org/docs/current/howto/ssi.html [Accessed 25 Feb. 2018].

Httpd.apache.org. (2018). Authentication and Authorization - Apache HTTP Server Version


2.4. [online] Available at: https://httpd.apache.org/docs/2.4/howto/auth.html [Accessed 25
Feb. 2018].

Httpd.apache.org. (2018). mod_deflate - Apache HTTP Server Version 2.4. [online]


Available at: https://httpd.apache.org/docs/2.4/mod/mod_deflate.html [Accessed 25 Feb.
2018].

Linuxquestions.org. (2018). Disabling HEAD, OPTIONS HTTP METHODS in Apache


Webserver. [online] Available at: https://www.linuxquestions.org/questions/linux-security-
4/disabling-head-options-http-methods-in-apache-webserver-763347/ [Accessed 25 Feb.
2018].

Wasson, M. (2018). Content Negotiation in ASP.NET Web API. [online]


Docs.microsoft.com. Available at: https://docs.microsoft.com/en-us/aspnet/web-
api/overview/formats-and-model-binding/content-negotiation [Accessed 25 Feb. 2018].

14

Вам также может понравиться