Ravindra BagaleCourses & study guides

Chapter 8: Configuring Nginx and Apache

Practice Questions and Lab Exercises

  1. Draw the four questions a web server answers for every request and name the directive for each in Nginx and Apache.
  2. Write the site-file location and enable method for Nginx and Apache on Ubuntu and on Amazon Linux 2023.
  3. Why is Ubuntu's default Apache site named 000-default.conf?
  4. What does Options -Indexes do? What is its Nginx equivalent?
  5. Lab: Move your Nginx site to /var/www/portfolio, then (on CentOS Stream 9) to /srv/portfolio using semanage fcontext.
  6. Lab: Run a second site on port 8081 with Apache. Open it in the security group from My IP only.
  7. Lab: Host site1.example.com and site2.example.com plus a catch-all default on one server. Verify all three with curl -H "Host: ...".
  8. Lab: Hide the server version and check the Server: header with curl -I before and after.
  9. Lab: Deliberately remove a ; from your server block and read the nginx -t error message.

Quick Revision

  • Four questions per request: port (listen/Listen) → site (server_name/ServerName, Host header) → folder (root/DocumentRoot) → file (index/DirectoryIndex).
  • Site files: conf.d/*.conf (AL2023/CentOS), sites-available + symlink or a2ensite (Ubuntu). Never edit main files for a site.
  • Fallback site: Nginx default_server or first block; Apache first vhost loaded (000-default.conf). Inspect with nginx -T / apachectl -S.
  • Change root: new folder 755/644 → update root / DocumentRoot and <Directory> → CentOS: semanage fcontext + restorecon for paths outside /var/www.
  • New port: config + security group + firewalld + semanage port (CentOS).
  • Workflow: backup (.bak) → edit → nginx -t / apachectl configtest → sudo service ... reload → curl -I → logs.