Ravindra BagaleCourses & study guides

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

  1. 8.1Where the configuration lives
  2. 8.2Reading an Nginx configuration
  3. 8.3Task: change the Nginx document root
  4. 8.4Reading an Apache configuration
  5. 8.5Task: change the Apache DocumentRoot
  6. 8.6Task: run a site on a different port
  7. 8.7Multiple sites with name-based virtual hosts
  8. 8.8Useful everyday configurations
  9. 8.9The safe change workflow
  10. 8.10Troubleshooting configuration problems

Review and practice

  1. ★Common Mistakes I See Students Make
  2. ★Interview Questions
  3. ★Practice Questions and Lab Exercises