Lab objective
Serve home.html from /var/www/course-site on TCP 8080. Use a dedicated lab configuration and retain an SSH session. Create the root and page first:
sudo mkdir -p /var/www/course-site
printf '<h1>Course site on 8080</h1>\n' | sudo tee /var/www/course-site/home.htmlApache configuration
On AL2023 save as /etc/httpd/conf.d/course-site.conf. On Ubuntu save as /etc/apache2/sites-available/course-site.conf and enable with sudo a2ensite course-site. Add Listen 8080 exactly once; on Ubuntu it can go in ports.conf instead of the site file.
Listen 8080
<VirtualHost *:8080>
ServerName course.example.com
DocumentRoot /var/www/course-site
DirectoryIndex home.html
<Directory /var/www/course-site>
Require all granted
Options -Indexes
AllowOverride None
</Directory>
</VirtualHost>Test with apachectl configtest on AL2023 or apache2ctl configtest on Ubuntu, then reload httpd or apache2. <VirtualHost *:8080> alone does not make Apache listen on 8080; Listen does.
Nginx equivalent
Use this as an alternative, not concurrently on the same 8080 socket. Save under an included conf.d path.
server {
listen 8080;
server_name course.example.com;
root /var/www/course-site;
index home.html;
location / { try_files $uri $uri/ =404; }
}Run sudo nginx -t then reload. Test:
curl -i -H 'Host: course.example.com' http://127.0.0.1:8080/
sudo ss -lntpNetwork and host controls
Allow 8080 only from your lab client's address in the EC2 security group. A host firewall, if enabled, must also permit the traffic. Under SELinux enforcing policy, a nonstandard listener or new directory may need an appropriate port type or file context; inspect getenforce and audit logs. Do not blindly copy policy changes into an unrelated server.
Verify, diagnose, revert
Expected result: HTTP 200 and the custom heading. 404 suggests wrong root/path/index; 403 suggests directory permission or policy; timeout suggests a network boundary. Restore the original config or remove only this lab site, test syntax, reload and remove the temporary security-group rule. Confirm port 8080 is no longer listening if it was lab-only.
Official reference
Ravindra’s Tip
Root, port और index बदलने के बाद guess मत करो। Config test, reload, local curl और remote test—यही क्रम रखो।
Interview and revision check
Why does an Apache VirtualHost on 8080 need a Listen directive?
VirtualHost defines request handling for that address/port. Listen creates the listener; defining the virtual host alone is insufficient.
Ravindra Bagale · Cloud & DevOps Academy · Handbook and project downloads