A Docker Compose setup for securely serving applications using Nginx with HTTPS (TLS) and basic authentication. This project configures SSL/TLS certificates and user authentication to protect and restrict access to your application.
├── app
│ ├── Dockerfile
│ ├── main.py
│ └── requirements.txt
├── auth # .htpasswd for user authentication (not in Git)
├── certs # SSL/TLS certificates (not in Git)
│ ├── server.crt
│ ├── server.csr
│ └── server.key
├── docker-compose.yml
├── LICENSE
├── nginx
│ ├── Dockerfile
│ └── nginx.conf
└── README.md
openssl genrsa -out certs/server.key 2048
openssl req -new -key certs/server.key -out certs/server.csr
openssl x509 -req -days 365 -in certs/server.csr -signkey certs/server.key -out certs/server.crt
sudo apt-get install apache2-utils
Note: Remember the password you set for
user1
in the.htpasswd
file. You will need this password to access the secured area of the application.
mkdir -p ./auth
htpasswd -c ./auth/.htpasswd user1
docker-compose up --build -d
Visit https://localhost:8443 and login with the username(user1
) and password you created before.
Note:
- The auth and certs directories are included in .gitignore for security reasons.
- Ensure that ports 8080 and 8443 are available on your host machine.
- The browser may show a warning that the connection is not secure. This is because a self-signed certificate is used for HTTPS. For production, you should obtain a certificate from a trusted Certificate Authority (CA) and configure it for your specific domain to avoid such warnings and ensure a secure connection.
docker-compose down
docker system prune
docker volume prune
Distributed under the Apache License. See LICENSE for more information.