Complete the code to serve static files from the /var/www/html directory.
location / {
root [1];
}root with alias.The root directive sets the directory from which static files are served. /var/www/html is the standard directory for static content.
Complete the code to enable index file serving for static content.
location / {
root /var/www/html;
[1] index.html index.htm;
}autoindex instead of index to serve default files.index keyword incorrectly.The index directive specifies the default files nginx looks for when a directory is requested.
Fix the error in the code to correctly serve static files with caching headers.
location /static/ {
root /var/www/html;
add_header Cache-Control [1];
}The add_header directive requires the header value to be in quotes if it contains special characters like '='.
Fill both blanks to configure nginx to serve static files and disable directory listing.
location /files/ {
root [1];
autoindex [2];
}autoindex to on, which allows directory listing.The root directive sets the directory for static files. autoindex off; disables directory listing for security.
Fill all three blanks to create a location block that serves static files with gzip compression and caching.
location /assets/ {
root [1];
gzip [2];
add_header Cache-Control [3];
}Serving static files from /usr/share/nginx/assets with gzip compression enabled (gzip on;) improves speed. Adding caching headers with "max-age=86400" caches files for one day.