Please answer the quiz and click the "Test" button at the bottom right.This quiz is part of the DevOpsTheHardWay course.
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?
-
nginx -s stop
-
nginx -s quit
-
nginx -s reload
-
kill -s QUIT $(cat /var/run/nginx.pid)
-
nginx -s reopen
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).
- The entire service has been restarted. Client's connection to the server might get dropped.
- The Nginx service reloads configurations without stopping the server.
- On syntax error, the server would not recover after restarted.
- That method, not only the master process is being restarted, but also the workers.
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).
- The entire service has been restarted. Client's connection to the server might get dropped.
- The Nginx service reloads configurations without stopping the server.
- On syntax error, the server would not recover after restarted.
- That method, not only the master process is being restarted, but also the workers.
Question 4
A Nginx server is running on a VM with 4 CPUs. How many workers it is advisable to be run?
- 1
- 4
- 8
- There is no any thumb rule.
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:
-
/etc/nginx/nginx.conf
-
/etc/nginx/conf.d/default.conf
-
/etc/nginx/nginx-custom.conf
-
/var/run/nginx/nginx.conf
- None of the above
Question 6
How many workers are currently running ?
- 1
- 2
- 3
- 4
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?
- 1
- 2
- 3
- 4
- None of the above
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/
:
- The client will be redirected to
http://localhost:8000
. - The client will be answered with
Server not found
since there is not running server underlocalhost:8000
on his local machine. - The client is not aware of
http://localhost:8000
. - The client URI is invalid.
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?
- Nginx will return a 405 Not Acceptable.
- Nginx will return a 406 Not Acceptable.
- Nginx will return a 404 Not Found.
- Nginx will return a 405 Bad request.
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
?
-
/
-
/images/
-
/images/profiles/
- None of them
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
?
-
/
-
/images/
-
^/users/([0-9]+)/
- None of them
Question 12
Which of them will serve an HTTP GET request with URI: /images/users/123
?
-
/
-
/images/
-
^/users/([0-9]+)/
- None of them
Question 13
Which of them will serve an HTTP GET request with URI: /users/1
?
-
/
-
/images/
-
^/users/([0-9]+)/
- None of them
Question 14
Which of them will serve an HTTP GET request with URI: /users/
?
-
/
-
/images/
-
^/users/([0-9]+)/
- None of them
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.
- The first
server
directive will serve the request, in both versions. - Both versions will serve
example.org
as.org
is prior to.net
in TLD level. - The request will not be served at all, an 201 status code is returned.
- None of the above.
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?
- Nginx machine's IP
- The client's IP
-
localhost
- None of the above
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)?
- The web application is not accessible that way.
- The web application is accessible only for internal usage.
- The uWSGI server only needs to listen for requests coming from the reverse proxy.
- None of the above