## nginx-serving-static-files-directory `/usr/local/etc/nginx.conf` or `/etc/nginx/nginx.conf` Below config would serve `/somewhere` directory files ``` ..... location / { autoindex on; alias /somewhere; # root /somewhere; } ..... ``` ### add basic auth #### generate basic auth file `htpasswd -bdc basic-auth-file admin 12345` `cat basic-auth-file` #### nginx config ``` location / { auth_basic "Restricted Area for Private Use Only"; auth_basic_user_file /basic-auth-file; autoindex on; root /somewhere; } ``` ### daemon off for debugging add below to top of `nginx.conf` ``` daemon off; error_log /dev/stdout info; ``` now run `nginx` would run without daemon from: https://stackoverflow.com/a/23328458/6414615 https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content/ https://stackoverflow.com/questions/9454150/nginx-password-protected-dir-with-autoindex-feature https://www.jianshu.com/p/1c0691c9ad3c