Ravindra BagaleCourses & study guides

Chapter 8: Configuring Nginx and Apache

Interview Questions

Q1. What is a server block in Nginx and a virtual host in Apache?
A configuration section that defines one website: the port it listens on, the host names it answers (server_name / ServerName), its document root and its rules and logs. Many can exist on one server.
Q2. How does Nginx decide which server block handles a request?
It matches the port in listen, then the Host header against server_name (exact, then wildcard, then regex). If nothing matches, it uses the default_server for that port, or the first block defined.
Q3. You changed the DocumentRoot and now get 403 Forbidden. What do you check?
File/folder permissions along the path (namei -l), a matching <Directory> with Require all granted, the index file, and on SELinux systems the context (ls -Z, fix with semanage fcontext + restorecon).
Q4. How do you run Apache on port 8081?
Add Listen 8081 (Ubuntu: ports.conf), create <VirtualHost *:8081>, test and reload, open the port in the security group/firewall, and on CentOS allow it with semanage port -a -t http_port_t -p tcp 8081.
Q5. What is the difference between reload and restart?
Reload applies new configuration gracefully without dropping connections and keeps the old config if the new one is invalid. Restart stops and starts the service, briefly interrupting traffic.
Q6. How do you see which virtual hosts Apache has loaded?
sudo apachectl -S (Ubuntu: sudo apache2ctl -S). For Nginx, sudo nginx -T dumps the full loaded configuration.
Q7. How do you redirect www.example.com to example.com?
A separate block for www.example.com with return 301 http://example.com$request_uri; (Nginx) or Redirect permanent / http://example.com/ (Apache).