ITNuvoAkademiya
Academy homePackagesPlaylistsToolsSubnet calculatorSearchGlossary
CiscoCCNA · CCNA: networking fundamentals1. Introduction2. Network Fundamentals3. Network Access4. IP Connectivity5. IP Services6. IPv67. Security Fundamentals8. AutomationCCNP: Enterprise networks · coming soon
LinuxLinux: system administrator üçün · Linux for system administrators1. Getting to know Linux2. Working with text3. Users and permissions4. Processes and packages5. Inside the system6. Monitoring and logs7. NetworkingRed Hat Enterprise Linux · Red Hat Enterprise Linux: from beginner to advanced1. Getting started2. Packages3. Users and permissions4. SELinux5. Services6. Storage7. Networking8. Building services9. Boot and recovery10. DevOps11. Security and monitoring
FortinetFortiGate Administrator · FortiGate Administrator: from first login to ZTNA1. Getting to know FortiGate2. Routing, policy and NAT3. Security profiles4. Users and logs5. Resilience, SD-WAN and automation6. VDOM7. VPN and ZTNA8. Proxy9. DMZ
MonitoringZabbix · Zabbix: from installation to alerts1. Introduction2. Installation and the database3. Basics: groups, templates, users4. Connecting devices5. Alerts, Grafana and the API
VirtualizationProxmox VE · coming soonVMware ESXi · coming soon
My account / Sign in
AZENRU
← itnuvo.com

The web server: httpd, virtual hosts, with SELinux and firewalld

Lesson 8.110 minAdvancedDecember 1, 2026
Open

This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.

Key points

  • httpd configuration: the main /etc/httpd/conf/httpd.conf, our own files in /etc/httpd/conf.d/*.conf; check with httpd -t (apachectl configtest).
  • A virtual host: several sites on one IP, told apart by ServerName: <VirtualHost *:80> ServerName shop.itnuvo.local DocumentRoot /srv/shop </VirtualHost>.
  • For a new DocumentRoot: directory permissions + a <Directory> block + the SELinux context (semanage fcontext + restorecon).
  • The sequence: dnf install → configuration → httpd -t → enable --now → firewall-cmd → SELinux → curl.
  • Logs: /var/log/httpd/error_log, access_log; write separate logs for each vhost.

The target architecture

In the simulator's lab world, srv-web01 is the web server, srv-db01 the database and client01 the user. In this unit we fill it with real services:

text
client01 (10.20.0.50)
   │  http://www.itnuvo.local, http://shop.itnuvo.local
   ▼
srv-web01 (10.20.0.15) — httpd: two virtual hosts
   │  3306/tcp (8.2), NFS (8.3)
   ▼
srv-db01 (10.20.0.20) — MariaDB, NFS

Steps 1–3: install, start, open

Familiar from the previous units:

srv-web01
[ali@srv-web01 ~]$ sudo dnf install -y httpd
[ali@srv-web01 ~]$ sudo systemctl enable --now httpd
[ali@srv-web01 ~]$ sudo firewall-cmd --permanent --add-service=http && sudo firewall-cmd --reload
[ali@srv-web01 ~]$ curl -s -o /dev/null -w "%{http_code}\n" http://localhost
403

403 is not surprising: /var/www/html is empty and RHEL's "welcome" page is returned with a 403 code. A browser shows the "Test Page".

Configuration files

File / directoryWhat it is
/etc/httpd/conf/httpd.confThe main configuration — Listen 80, DocumentRoot "/var/www/html", User apache
/etc/httpd/conf.d/*.confExtra configuration — put your own sites here
/etc/httpd/conf.modules.d/Module loading
/var/www/htmlDefault content
/var/log/httpd/access_log, error_log

On RHEL httpd processes run as the apache user (www-data on Ubuntu).

The first site: in the standard directory

srv-web01
[ali@srv-web01 ~]$ sudo mkdir -p /var/www/www.itnuvo.local
[ali@srv-web01 ~]$ echo "<h1>ITNuvo - ana sayt</h1>" | sudo tee /var/www/www.itnuvo.local/index.html
[ali@srv-web01 ~]$ sudo tee /etc/httpd/conf.d/www.conf > /dev/null <<'EOF'
<VirtualHost *:80>
    ServerName www.itnuvo.local
    DocumentRoot /var/www/www.itnuvo.local
    ErrorLog /var/log/httpd/www-error.log
    CustomLog /var/log/httpd/www-access.log combined
</VirtualHost>
EOF
[ali@srv-web01 ~]$ sudo httpd -t
Syntax OK
[ali@srv-web01 ~]$ sudo systemctl reload httpd

A directory created under /var/www gets the SELinux context (httpd_sys_content_t) automatically — no extra work needed.

The second site: /srv/shop — four layers

srv-web01
[ali@srv-web01 ~]$ sudo mkdir -p /srv/shop
[ali@srv-web01 ~]$ echo "<h1>ITNuvo Shop</h1>" | sudo tee /srv/shop/index.html
[ali@srv-web01 ~]$ sudo tee /etc/httpd/conf.d/shop.conf > /dev/null <<'EOF'
<VirtualHost *:80>
    ServerName shop.itnuvo.local
    DocumentRoot /srv/shop
    <Directory /srv/shop>
        Require all granted
    </Directory>
    ErrorLog /var/log/httpd/shop-error.log
    CustomLog /var/log/httpd/shop-access.log combined
</VirtualHost>
EOF
[ali@srv-web01 ~]$ sudo httpd -t && sudo systemctl reload httpd
[ali@srv-web01 ~]$ curl -s -o /dev/null -w "%{http_code}\n" -H "Host: shop.itnuvo.local" http://localhost
403

The configuration is right, but 403. Let us check the four layers:

LayerCheckResult
1. httpd configurationThe <Directory> block, Require all granted✓ (httpd sets Require all denied for / by default — without the block, 403)
2. File permissionsls -ld /srv/shop, ls -l /srv/shop✓ 755 / 644 — apache can read
3. SELinuxls -Zd /srv/shop✗ var_t
4. FirewallA local request, not affected—
srv-web01
[ali@srv-web01 ~]$ ls -Zd /srv/shop
unconfined_u:object_r:var_t:s0 /srv/shop
[ali@srv-web01 ~]$ sudo semanage fcontext -a -t httpd_sys_content_t "/srv/shop(/.*)?"
[ali@srv-web01 ~]$ sudo restorecon -Rv /srv/shop
Relabeled /srv/shop from unconfined_u:object_r:var_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0
Relabeled /srv/shop/index.html from unconfined_u:object_r:var_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0
[ali@srv-web01 ~]$ curl -s -H "Host: shop.itnuvo.local" http://localhost
<h1>ITNuvo Shop</h1>

This is the most classic RHCSA task — and it is solved without turning SELinux off.

Checking from the client

On client01 we write the names into /etc/hosts (on a real network they would be in DNS):

client01
ali@client01:~$ echo "10.20.0.15 www.itnuvo.local shop.itnuvo.local" | sudo tee -a /etc/hosts
ali@client01:~$ curl -s http://www.itnuvo.local
<h1>ITNuvo - ana sayt</h1>
ali@client01:~$ curl -s http://shop.itnuvo.local
<h1>ITNuvo Shop</h1>

The same IP, two different sites — httpd looks at the Host header of the request and chooses the right VirtualHost.

HTTPS (briefly)

srv-web01
[ali@srv-web01 ~]$ sudo dnf install -y mod_ssl
[ali@srv-web01 ~]$ sudo firewall-cmd --permanent --add-service=https && sudo firewall-cmd --reload
[ali@srv-web01 ~]$ sudo systemctl restart httpd
[ali@srv-web01 ~]$ curl -sk -o /dev/null -w "%{http_code}\n" https://localhost
403

mod_ssl opens 443 with a self-signed certificate. In production a real certificate is configured (SSLCertificateFile, SSLCertificateKeyFile); the key file must have mode 600 and the cert_t context.

When there is a problem

srv-web01
[ali@srv-web01 ~]$ sudo tail -n 3 /var/log/httpd/shop-error.log
[ali@srv-web01 ~]$ sudo ausearch -m AVC -ts recent -c httpd
[ali@srv-web01 ~]$ sudo httpd -S
VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server shop.itnuvo.local (/etc/httpd/conf.d/shop.conf:1)
         port 80 namevhost shop.itnuvo.local (/etc/httpd/conf.d/shop.conf:1)
         port 80 namevhost www.itnuvo.local (/etc/httpd/conf.d/www.conf:1)

httpd -S shows all virtual hosts and which one is the default — when the Host header matches none of them, the first file in alphabetical order (here shop.conf) answers.

Lab: two sites

In the Red Hat simulator, the "Start httpd", "firewalld: open the site to the network" and "SELinux: 403 Forbidden" tasks are the main steps of this lesson — do all three in order. Then on your own VM:

  1. Build the www.itnuvo.local site in /var/www/www.itnuvo.local.
  2. Build the shop.itnuvo.local site in /srv/shop: <Directory>, permissions, semanage fcontext.
  3. httpd -t, reload, httpd -S.
  4. Open both sites by name from client01.

Check: two curl commands return two different pages; getenforce → Enforcing.

Check yourself

5 questions · answers are shown instantly · 3 correct answers complete the lesson

1Where should you create your own virtual host file on RHEL?

Files in conf.d are loaded automatically.

2Which command checks the syntax of the httpd configuration?

apachectl configtest does the same.

3The site is in /srv/shop, the permissions are 755/644, the Directory block exists, but it returns 403. What is the next step?

/srv is var_t by default.

4How does httpd tell several sites on one IP apart?

This is called name-based virtual hosting.

5Which user do httpd processes run as on RHEL?

www-data on Ubuntu.
Was this lesson useful?

Comments

Sign in to comment.