This quiz is part of the DevOpsTheHardWay course.

Please answer the quiz and click the "Test" button at the bottom right.

Webservers - Nginx - self-check questions

Question 1

Server administrator shuts down a Nginx server while allow the webserver to serve the remaining processes requests (graceful termination). Which command(s) did she use?

Question 2

Server administrator made some changes to the Nginx main configuration file (/etc/nginx/nginx.conf). Then performed sudo systemctl restart nginx. Choose the correct sentence(s).

Question 3

Server administrator made some changes to the Nginx main configuration file (/etc/nginx/nginx.conf). Then performed sudo nginx -s reload. Choose the correct sentence(s).

Question 4

A Nginx server is running on a VM with 4 CPUs. How many workers it is advisable to be run?

Given the below output of Nginx service status:

● nginx.service - nginx - high performance web server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-04-01 09:29:38 UTC; 29min ago
       Docs: https://nginx.org/en/docs/
    Process: 440 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx-custom.conf (code=exited, status=0/SUCCESS)
   Main PID: 479 (nginx)
      Tasks: 3 (limit: 1111)
     Memory: 4.1M
        CPU: 15ms
     CGroup: /system.slice/nginx.service
             ├─479 "nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx-custom.conf"
             ├─480 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
             └─481 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Answer the below 2 questions.

Question 5

Which of the following config files the server admin should edit in order to change the server's configurations:

Question 6

How many workers are currently running ?

Question 7

A Nginx server with default configuration. Given the below output of netstat -tuna command executed from the server's machine:

myuser@hostname:~$ netstat -tuna
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:3031          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     
tcp        0      0 172.31.46.24:80         93.172.114.143:47878    ESTABLISHED
tcp        0      0 127.0.0.1:3031          127.0.0.1:47792         TIME_WAIT  
tcp        0      0 127.0.0.1:47776         127.0.0.1:3031          TIME_WAIT  
tcp        0      0 127.0.0.1:3031          127.0.0.1:47788         TIME_WAIT    
tcp        0      0 172.31.46.24:80         14.101.201.16:47850    ESTABLISHED
tcp        0      0 172.31.46.24:80         33.9.115.215:47864    ESTABLISHED
tcp        0      0 127.0.0.1:3031          127.0.0.1:47760         TIME_WAIT  

How many clients are currently hold an open socket connection with the server?

Question 8

Given the below reverse proxy server configurations:

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://localhost:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

And given a client visits http://example.com/:

Question 9

Given a Nginx server with the default configuration. What happens when a client performs an HTTP request with the header Accept: audio/wav?

Hint: Take a look on where /etc/nginx/nginx.conf includes the /etc/nginx/mime.types file. What does it do?

Question 10

Given the below 3 location directives:

location / {
    ...
}

location /images/ {
    ...
}

location /images/profiles/ {
    ...
}

Which of them will serve an HTTP GET request with URI: /images/123.png?

Given the below 3 location directives:

location / {
    ...
}

location /images/ {
    if ($request_method = POST) {
        return 400
    }
}

location location ~* ^/users/([0-9]+)/ {
    ...
}

Answer the below 4 questions.

Tip: Use regex101. Copy te expression ^/users/([0-9]+)/ and test some string examples.

Question 11

Which of them will serve an HTTP POST request with URI: /images/123.png?

Question 12

Which of them will serve an HTTP GET request with URI: /images/users/123?

Question 13

Which of them will serve an HTTP GET request with URI: /users/1?

Question 14

Which of them will serve an HTTP GET request with URI: /users/?

Question 15

Given the below 2 different server directives:

Version 1:

server {
    listen      80;
    server_name example.org www.example.org;
    ...
}

server {
    listen      80;
    server_name example.net www.example.net;
    ...
}

Version 2:

server {
    listen      80;
    server_name example.net www.example.net;
    ...
}

server {
    listen      80;
    server_name example.org www.example.org;
    ...
}

You are told that the machine's IP is 112.57.8.0. You open your local browser, type 112.57.8.0 and hit the Enter key.

Question 16

Given the below reverse proxy configuration:

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://localhost:8080;
    }
}

If a client sends an HTTP request to a web application (Flask) that is behind a reverse proxy (Nginx), which IP address will the web application see as the source of the request?

Question 17

An uWSGI server is running the configuration under simple_flask_webserver/uwsgi.ini. Server administrator wants to inspect the socket that the uWSGI server is listening on:

myuser@hostname:~$ netstat -tuna
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:3031          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN                        
tcp        0      0 127.0.0.1:3031          127.0.0.1:51054         TIME_WAIT  
tcp6       0      0 :::22                   :::*                    LISTEN     

How could the uWSGI server accepts requests from clients, if the only socket it is listening 127.0.0.1:3031 (which means accepting connection from 127.0.0.1 only)?

license