If you can see this check that

  • Javascript is enabled

HTTP Server

This tutorial is concerned with the configuration of an http server, namely Apache.

To reset all the check buttons from a previous attempt click here

Question 1 Run the apache server

Each time you make a configuration change to the Apache server you must restart (or at the very least reload) the http service. Remember to start apache for the first time do:

systemctl start httpd.service
And to reload the configuration file do:
systemctl reload httpd.service
Additionally if you have been changing the standard firewall configuration, you should reset the config to normal. To do this do:
systemctl restart nftables.service

Now start the webserver with the default configuration.

Tests: Ready
 
Run apache UNTESTED

Question 2 Add HOST directories and files

First create some files to use as part of a new virtual host.

Create a directory to be the document root of your new virtual host. This is within a system directory, so use sudo. Give alice ownership and give the file group ownership of whatever alice's default group is.

  /var/www/html/myhost/
  

In that directory create a file called hello.html. Do this as alice. The contents of this file should be:

<html>
<body>
<h1>HOST</h1>
<p>
I am clever
</p>
</body>
</html>

Ensure apache will have access to the file and directory by checking that other has execute access on the directory and read access on the file. Alice obviously needs rwx on the directory and rw on the file. For both the directory and the file set the group permissions to none. More generous permissions or permission changes the default will be marked incorrect. This style of permissions and ownership is expected for all document roots and files you create in this tutorial.

Copy this file to data.html in the same directory, preserving ownership and permissions. So:

  /var/www/html/myhost/data.html
  

Once copied, change the word "HOST" in data.html to the word "DATA". Make no other changes.

Tests: Ready
 
myhost exists UNTESTED
myhost Ownership and permissions UNTESTED
hello exists UNTESTED
hello Ownership and permissions UNTESTED
hello contains HOST UNTESTED
hello selinux ok UNTESTED
data exists UNTESTED
data Ownership and permissions UNTESTED
data contains DATA UNTESTED
data selinux ok UNTESTED

Question 3 My HOST name

When your web server is running, you will be able to direct your own computer's browser to your web page using an external URL. Eventually this will be something like:

http://yourmachinename/hello.html

Replace "yourmachinename" with the HOST version of your virtual machine. You can get that from the CONNECT tab of the control panel in the "VM WEB" entry, or by taking the last two octets of the VM IP and inserting them into "host-O3-O4.linuxzoo.net", or by running this easy-to-remember command:

[alice@alma10 dave]$ hostname -I
10.0.19.17
[alice@alma10 dave]$ hostname -I | tr ' ' '\n' | grep '^10\.' | sed -E 's/10\.0\.([0-9]+)\.([0-9]+)/host-\1-\2.linuxzoo.net/'
host-19-17.linuxzoo.net

In linuxzoo, we give you 3 names for your machine. The HOST version as shown above (starting host-), as well as a VM and a WEB version. These other versions are just the same name as the HOST version, but with the word "host" substituted for "vm" or "web". Do note that your IP number can change each time you reave and join the queue, so if you get half-way through configuring and take a break, you need to recalculate the name of your VM and edit the config files to suit the change.

Using any of those techniques identified above, what is the HOST version of your VM currently?

Tests: Ready
 
VM HOST name correct UNTESTED

Question 4 Configure HOST VM

You need to create a virtual host for your virtual machine. In this case you are using the HOST version of your VM. These should go into a new file somewhere in /etc/httpd/conf.d. For the purposes of this tutorial, create and use the file "/etc/httpd/conf.d/zvirtual.conf".

Using <VirtualHost> create a VirtualHost in the file /etc/httpd/conf.d/zvirtual.conf. Below is an example of a VirtualHost definition which may help you remember what is needed.

<VirtualHost *:80>
    ServerAdmin me@null.com
    DocumentRoot /home/gordon/public_html/grussell.org
    ServerName sql.grussell.org
    ErrorLog logs/tutorial-error_log
    CustomLog logs/tutorial-access_log common
</VirtualHost>

The name of your virtual host has to be worked out by yourself from your current hostname, which you should have done in the previous question. The document root was created in a previous question too, i.e.

  /var/www/html/myhost/
  

IMPORTANT: Do not just copy the virtualhost example, as your machine number is likely to be entirely different. You need to work out your machine name for yourself as well as the documentroot. Note too that your hostname can change each time you reboot, so double check each time you reboot! The other fields are not important in this question.

It is easy to make a syntax error in the config file. If you have problems you can check for syntax errors using the command:

httpd -t
...and if you make changes to a configuration file remember to tell httpd.service!

Once again you can verify this works manually by pointing your browser to host-?-?.linuxzoo.net/hello.html or the vm equivalent (remembering to put the right things in for the "?" characters). This is important, as in an assessment you may need to verify this yourself.

Tests: Ready
 
VirtualHost config detected for host-?-?.linuxzoo.net UNTESTED
http://host-?-?.linuxzoo/hello.html contains HOST UNTESTED

Question 5 Add a new document root

Create the following directory:

In the new directory create a file called "hello.html", which is a copy of the hello.html from /var/www/html/myhost/, except in "web/hello.html" replace the word HOST with WEB. Case is important. Make not other changes

Follow the permissions and ownership model as before, so alice owns the directory and file, and the directory has full access to alice, and execute only for other, and the file is owned by alice with read and write and readable by other. No group permissions, but make sure group ownership is as expected for files and directories owned by alice.

Tests: Ready
 
web exists UNTESTED
web Ownership and permissions UNTESTED
hello exists UNTESTED
hello Ownership and permissions UNTESTED
hello contains WEB UNTESTED
hello selinux ok UNTESTED

Question 6 Create WEB virtual host

Create a second virtual host after the first one you created in "/etc/httpd/conf.d/zvirtual.conf". This is similar to the first one, except uses the WEB version of your VM's name, and has a document root of the web directory you created in the previous question. IN ADDITION, make this second virtual host entry have an alias so it will also respond to the VM vesion of your VM's name. So the WEB version of the name starts "web-" and the VM version of the name starts "vm-".

For example, if your HOST name is:

host-3-2.linuxzoo.net

then your WEB and VM names are:

web-3-2.linuxzoo.net
vm-3-2.linuxzoo.net

Each VirtualHost area needs its own ServerName and DocumentRoot. As before the other fields are not important in this question.

Once again you can verify this works manually by pointing your browser to web-?-?.linuxzoo.net/hello.html or the vm equivalent (remembering to put the right things in for the "?" characters). This is important, as in an assessment you may need to verify this yourself. Also check the vm- version with hello.html. If you forget the "hello.html" part you will likely get an error, as there is no index.html default file in this exercise.

Tests: Ready
 
VirtualHost config detected for web-?-?.linuxzoo.net UNTESTED
http://web-?-?.linuxzoo/hello.html contains WEB UNTESTED
VirtualHost config alias for vm-?-?.linuxzoo.net UNTESTED
http://vm-?-?.linuxzoo/hello.html contains WEB UNTESTED
Safety-check: only two virtualhost definitions UNTESTED

Question 7 Rewrite Rules

Add to the end of the VirtualHost tag area for web-?-? a rewrite rule, such that any use of the alias vm-?-?.linuxzoo.net gets an external redirection to rewrite it to host-?-?.linuxzoo.net/hello.html.

Tests: Ready
 
http://web-?-?.linuxzoo/hello.html contains WEB UNTESTED
http://vm-?-?.linuxzoo/hello.html contains HOST UNTESTED
http://vm-?-?.linuxzoo/hello.html is redirect UNTESTED
http://vm-?-?.linuxzoo/random is redirect to hello UNTESTED

Question 8 Extended Rewrite Conditions

Add a new set of rewrite rules BEFORE the previous rules, so that vm-?-?.linuxzoo.net/data.html gets rewritten using an external redirect to host-?-?.linuxzoo.net/data.html. Otherwise it just does the rules created in the previous quesiton. Thus:

http://vm-?-?.linuxzoo.net/hello.html   -> rewritten to -->  http://host-?-?.linuxzoo.net/data.html 
http://vm-?-?.linuxzoo.net/[anything]   -> Goes to the previous rules and thus rewritten to http://host-?-?.linuxzoo.net/hello.html
Tests: Ready
 
http://web-?-?.linuxzoo/hello.html contains WEB UNTESTED
http://vm-?-?.linuxzoo/hello.html contains DATA UNTESTED
http://vm-?-?.linuxzoo/hello.html is redirect UNTESTED
http://vm-?-?.linuxzoo/random is redirect to hello UNTESTED

Alma 10 introPaths | BasicShell | Search
Alma 10 tutorials:intro1 | intro2 | wildcard | permission | pipe | vi | essential | admin | net | SELinux1 | SELinux2 | fwall | DNS | diag | Apache1 | Apache2 | log | Mail
Caine 10.0Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Mock Exam
Caine 13.0Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Registry | Mock Exam
Kali 2020-41a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7 | 8a | 8b | 9 | 10
Kali 2024-41a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7 | 8a | 8b | 9 | 10
UsefulPrivacy Policy | Terms and Conditions

Linuxzoo created by Gordon Russell.
@ Copyright 2004-2026 Edinburgh Napier University