-
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 exec
to generate a.htpasswd
file 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.conf
file in the/path/on/host
directory 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