Chapter 8: Configuring Nginx and Apache
Mitranno, in Chapter 6 we installed Nginx and Apache, and in Chapter 7 we hosted our first sites by copy-pasting a server block. That was enough to get started, but in real projects you will be asked to change things. Move the website to another folder, run it on another port, host three sites on one server, redirect www or hide the version number. In this chapter we open the configuration files and understand them line by line. Once you can read a config file comfortably, you'll handle web servers with confidence. Chala, suru karuya!
Browser request: GET /about.html Host: site1.example.com (port 80)
|
+---------------------v----------------------+
| 1. Which listen port? listen 80 / Listen 80
| 2. Which site? server_name / ServerName (Host header)
| 3. Which folder? root / DocumentRoot
| 4. Which file? index / DirectoryIndex, location / <Directory>
+---------------------+----------------------+
|
/var/www/site1/about.html --> 200 OK
Every web server answers these four questions for every request. Once you know where each answer is written, you can configure any site.
Concepts in this chapter
- 8.1Where the configuration lives
- 8.2Reading an Nginx configuration
- 8.3Task: change the Nginx document root
- 8.4Reading an Apache configuration
- 8.5Task: change the Apache DocumentRoot
- 8.6Task: run a site on a different port
- 8.7Multiple sites with name-based virtual hosts
- 8.8Useful everyday configurations
- 8.9The safe change workflow
- 8.10Troubleshooting configuration problems