0
0
Nginxdevops~10 mins

Why static file serving is the primary use case in Nginx - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to serve static files from the /var/www/html directory.

Nginx
location / {
    root [1];
}
Drag options to blanks, or click blank then click option'
A/usr/share/nginx/html
B/etc/nginx/html
C/home/user/html
D/var/www/html
Attempts:
3 left
💡 Hint
Common Mistakes
Using a directory that does not exist or is not accessible by nginx.
Confusing root with alias.
2fill in blank
medium

Complete the code to enable index file serving for static content.

Nginx
location / {
    root /var/www/html;
    [1] index.html index.htm;
}
Drag options to blanks, or click blank then click option'
Aindex
Bautoindex on;
Cindex on;
Dautoindex off;
Attempts:
3 left
💡 Hint
Common Mistakes
Using autoindex instead of index to serve default files.
Adding a semicolon after index keyword incorrectly.
3fill in blank
hard

Fix the error in the code to correctly serve static files with caching headers.

Nginx
location /static/ {
    root /var/www/html;
    add_header Cache-Control [1];
}
Drag options to blanks, or click blank then click option'
A"no-cache"
Bno-cache
C"max-age=3600"
Dmax-age=3600
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the header value causing nginx to fail to start.
Using incorrect header values that do not control caching.
4fill in blank
hard

Fill both blanks to configure nginx to serve static files and disable directory listing.

Nginx
location /files/ {
    root [1];
    autoindex [2];
}
Drag options to blanks, or click blank then click option'
A/srv/static
Bon
Coff
D/var/www/files
Attempts:
3 left
💡 Hint
Common Mistakes
Setting autoindex to on, which allows directory listing.
Using incorrect directory paths that do not exist.
5fill in blank
hard

Fill all three blanks to create a location block that serves static files with gzip compression and caching.

Nginx
location /assets/ {
    root [1];
    gzip [2];
    add_header Cache-Control [3];
}
Drag options to blanks, or click blank then click option'
A/usr/share/nginx/assets
Bon
C"max-age=86400"
Doff
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to enable gzip compression.
Not quoting the Cache-Control header value.
Using wrong directory paths.