Web / NGINX Interview questions
How do you serve static files with NGINX?
Serving static files is one of NGINX's core strengths. The root directive points to a directory on disk, and NGINX maps the request URI onto a file path under it.
server { listen 80; server_name static.example.com; root /var/www/static; location / { try_files $uri $uri/ =404; } }
With this setup, a request for /images/logo.png is served directly from /var/www/static/images/logo.png without touching any application code. Adding expires and Cache-Control headers on top lets browsers cache these assets, reducing repeat requests to the server entirely.
More Related questions...