Enabling basic auth
-
Persist Nginx Configuration
Update docker-compose.yml to mount the Nginx configuration directory:volumes: - /path/on/host:/etc/nginx -
Generate Basic Auth Credentials
After starting the container, use thedocker execto generate a.htpasswdfile with your username and password. Run the following command on container host:docker exec -it <container_name> htpasswd -c /etc/nginx/.htpasswd <username> -
Edit Nginx Configuration
Edit thenginx.conffile in the/path/on/hostdirectory to include Basic Auth. Below is an example configuration:# ... Configuration before location / { try_files $uri $uri.html $uri/ =404; # Enable Basic Auth auth_basic "Protected Notes"; auth_basic_user_file /etc/nginx/.htpasswd; } # ... Configuration after -
Restart the container
