Categories
Uncategorized

How to serve single file using nginx

nginx configuration snippet to illustrate how to serve single file.

Serve statistics.csv file from /var/www/statistics/ directory for http://127.0.0.1:7000/statistics;csv;norefresh address, protect it using basic authentication and deny anything else.

server {
  listen 127.0.0.1:7000;
  root /var/www/statistics;
  location "/statistics;csv;norefresh" {
    auth_basic "Statistics";
    auth_basic_user_file /etc/nginx/snippets/statistics.htpasswd;
    try_files /statistics.csv =404;
  }
  location / {
    deny all;
  }
}

Simple as that.