DEV Community

Janak Shrestha
Janak Shrestha

Posted on Edited on

Apache Redirects

The Nautilus devops team got some requirements related to some Apache config changes. They need to setup some redirects for some URLs. There might be some more changes need to be done. Below you can find more details regarding that:

1.) httpd is already installed on app server 2. Configure Apache to listen on port 8086.

  1. Configure Apache to add some redirects as mentioned below:

    a.) Redirect http://stapp02.stratos.xfusioncorp.com:<Port>/ to http://www.stapp02.stratos.xfusioncorp.com:<Port>/ i.e non www to www. This must be a permanent redirect i.e 301

    b.) Redirect http://www.stapp02.stratos.xfusioncorp.com:<Port>/blog/ to http://www.stapp02.stratos.xfusioncorp.com:<Port>/news/. This must be a temporary redirect i.e 302.


📋 Challenge Requirements

  1. Apache (httpd) is already installed on Application Server 2 (stapp02). Configure Apache to listen on port 8086.
  2. Configure Apache redirects:
    • (a) http://stapp02.stratos.xfusioncorp.com:<Port>/ → http://www.stapp02.stratos.xfusioncorp.com:<Port>/ — permanent (301)
    • (b) http://www.stapp02.stratos.xfusioncorp.com:<Port>/blog/ → http://www.stapp02.stratos.xfusioncorp.com:<Port>/news/ — temporary (302)

Step 1: Log in to the Application Server

From the jump host, SSH into stapp02 as steve:

# Login: user=steve | password=Am3ric@ | host=stapp02 (10.244.240.188)
ssh steve@stapp02
Enter fullscreen mode Exit fullscreen mode

Output:

thor@jump-host ~$ ssh steve@stapp02
The authenticity of host 'stapp02 (10.244.240.188)' can't be established.
ED25519 key fingerprint is SHA256:gMtlah5U16R7LS+tjKpYIKMtAq1K14tnySASEzl7FoY.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'stapp02' (ED25519) to the list of known hosts.
steve@stapp02's password: 
[steve@stapp02 ~]$ 
Enter fullscreen mode Exit fullscreen mode

Step 2: Switch to root

All configuration changes require root privileges:

# Login: user=steve | password=Am3ric@ | sudo to root (same password)
sudo -i
Enter fullscreen mode Exit fullscreen mode

Output:

[steve@stapp02 ~]$ sudo -i

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for steve: 
[root@stapp02 ~]# 
Enter fullscreen mode Exit fullscreen mode

Step 3: Configure Apache to listen on port 8086

Edit the main Apache configuration file:

# Login: root@stapp02 | Edit: change "Listen 80" → "Listen 8086"
vi /etc/httpd/conf/httpd.conf
Enter fullscreen mode Exit fullscreen mode

Verify the change:

# Login: root@stapp02 | Verify the Listen directive
grep ^Listen /etc/httpd/conf/httpd.conf
Enter fullscreen mode Exit fullscreen mode

Output:

Listen 8086
Enter fullscreen mode Exit fullscreen mode

✅ Requirement 1 complete — Apache is now configured to listen on port 8086.


Step 4: (Optional) Allow the new port in SELinux

If SELinux is enforcing, you would normally allow the port with semanage. In this lab, the tool isn't installed — but it turns out not to be needed, since traffic reaches Apache successfully (proven later by curl):

# Login: root@stapp02 | Allow port 8086 in SELinux (not installed in this lab)
semanage port -a -t http_port_t -p tcp 8086
Enter fullscreen mode Exit fullscreen mode

Output:

-bash: semanage: command not found
Enter fullscreen mode Exit fullscreen mode

💡 Note: No problem — the lab environment doesn't block port 8086 via SELinux, so we can proceed.


Step 5: Create the redirect configuration file

Create a new virtual host config in /etc/httpd/conf.d/:

# Login: root@stapp02 | Create the redirect virtual host config
vi /etc/httpd/conf.d/redirect.conf
Enter fullscreen mode Exit fullscreen mode

Contents:

<VirtualHost *:8086>
    ServerName stapp02.stratos.xfusioncorp.com
    Redirect 301 / http://www.stapp02.stratos.xfusioncorp.com:8086/
</VirtualHost>

<VirtualHost *:8086>
    ServerName www.stapp02.stratos.xfusioncorp.com
    Redirect 302 /blog/ http://www.stapp02.stratos.xfusioncorp.com:8086/news/
</VirtualHost>
Enter fullscreen mode Exit fullscreen mode

💡 Why two VirtualHosts? The Redirect 301 / ... rule matches all paths. Splitting the rules into separate VirtualHost blocks (keyed by ServerName) ensures the /blog/ → /news/ rule applies only to the www host, without conflicting.


Step 6: Test the configuration syntax

Before restarting, validate the config:

# Login: root@stapp02 | Validate Apache config syntax
httpd -t
Enter fullscreen mode Exit fullscreen mode

Output:

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, 
using 10.244.240.188. Set the 'ServerName' directive globally to suppress this message
Syntax OK
Enter fullscreen mode Exit fullscreen mode

â„šī¸ AH00558 is just a warning, not an error. Syntax OK confirms the configuration is valid.


Step 7: Restart the Apache service

Apply the changes:

# Login: root@stapp02 | Restart Apache to apply changes
systemctl restart httpd
Enter fullscreen mode Exit fullscreen mode

(No output on success.)


Step 8: Verify the redirects with curl

Test (a): non-www → www (301 permanent)

# Login: root@stapp02 | Test non-www → www redirect
curl -I http://stapp02.stratos.xfusioncorp.com:8086/
Enter fullscreen mode Exit fullscreen mode

Output:

HTTP/1.1 301 Moved Permanently
Date: Wed, 25 Nov 2026 07:03:38 GMT
Server: Apache/2.4.62 (CentOS Stream)
Location: http://www.stapp02.stratos.xfusioncorp.com:8086/
Content-Type: text/html; charset=iso-8859-1
Enter fullscreen mode Exit fullscreen mode

✅ 301 Moved Permanently returned — requirement 2(a) complete.

Test (b): /blog/ → /news/ (302 temporary)

# Login: root@stapp02 | Test /blog/ → /news/ redirect
curl -I http://www.stapp02.stratos.xfusioncorp.com:8086/blog/
Enter fullscreen mode Exit fullscreen mode

Output:

HTTP/1.1 302 Found
Date: Wed, 25 Nov 2026 07:03:48 GMT
Server: Apache/2.4.62 (CentOS Stream)
Location: http://www.stapp02.stratos.xfusioncorp.com:8086/news/
Content-Type: text/html; charset=iso-8859-1
Enter fullscreen mode Exit fullscreen mode

✅ 302 Found returned — requirement 2(b) complete.


Step 9: Ensure Apache starts on boot (optional but recommended)

Check whether the service is enabled:

# Login: root@stapp02 | Check if Apache starts on boot
systemctl is-enabled httpd
Enter fullscreen mode Exit fullscreen mode

Output:

disabled
Enter fullscreen mode Exit fullscreen mode

Since it was disabled, enable it:

# Login: root@stapp02 | Enable Apache to start on boot
systemctl enable httpd
Enter fullscreen mode Exit fullscreen mode

Output:

Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service 
→ /usr/lib/systemd/system/httpd.service.
Enter fullscreen mode Exit fullscreen mode

✅ Apache will now start automatically on reboot.


✅ Final Summary

Requirement Result Proof
Apache listens on port 8086 ✅ Done Listen 8086 in httpd.conf
301 redirect: non-www → www ✅ Done HTTP/1.1 301 Moved Permanently
302 redirect: /blog/ → /news/ ✅ Done HTTP/1.1 302 Found
Apache enabled on boot ✅ Done systemctl is-enabled → enabled

🔑 Key Takeaways

  1. Listen directive controls the port Apache binds to — update it in /etc/httpd/conf/httpd.conf.
  2. Redirect 301 = permanent redirect; Redirect 302 = temporary redirect.
  3. Always run httpd -t before restarting to catch config errors.
  4. AH00558 is a harmless warning about the FQDN — not a failure.
  5. The semanage command may not be installed, but it's only needed when SELinux actually blocks the port — always verify with a real curl test rather than assuming.
  6. systemctl enable httpd ensures the service persists across reboots, which many graders check.

The challenge is now fully complete and ready to submit. 🎉

Top comments (0)