Chapter 8: Configuring Nginx and Apache
Practice Questions and Lab Exercises
- Draw the four questions a web server answers for every request and name the directive for each in Nginx and Apache.
- Write the site-file location and enable method for Nginx and Apache on Ubuntu and on Amazon Linux 2023.
- Why is Ubuntu's default Apache site named
000-default.conf? - What does
Options -Indexesdo? What is its Nginx equivalent? - Lab: Move your Nginx site to
/var/www/portfolio, then (on CentOS Stream 9) to/srv/portfoliousingsemanage fcontext. - Lab: Run a second site on port 8081 with Apache. Open it in the security group from My IP only.
- Lab: Host
site1.example.comandsite2.example.complus a catch-all default on one server. Verify all three withcurl -H "Host: ...". - Lab: Hide the server version and check the
Server:header withcurl -Ibefore and after. - Lab: Deliberately remove a
;from your server block and read thenginx -terror 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 ora2ensite(Ubuntu). Never edit main files for a site. - Fallback site: Nginx
default_serveror first block; Apache first vhost loaded (000-default.conf). Inspect withnginx -T/apachectl -S. - Change root: new folder 755/644 → update
root/DocumentRootand<Directory>→ CentOS:semanage fcontext+restoreconfor 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.