Skip to content

A Docker Compose setup for securely serving applications with Nginx, featuring HTTPS (TLS) and basic authentication. This project includes configuration for SSL/TLS certificates and user authentication to ensure your application is protected and accessible only to authorized users.

License

Notifications You must be signed in to change notification settings

Perpetue237/docker-compose-secure-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker compose secure application with TLS and authentication

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.

Project Structure

├── 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

Setup Instructions

Generate SSL Certificates

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

Install htpasswd Utility

sudo apt-get install apache2-utils

Create the .htpasswd File and user1

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

Build and Run the Docker Compose Setup

docker-compose up --build -d

Verify the Setup

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.

Stop the Application and Clean the System

docker-compose down
docker system prune
docker volume prune

License

Distributed under the Apache License. See LICENSE for more information.

Contact

Perpetue Kuete Tiayo

About

A Docker Compose setup for securely serving applications with Nginx, featuring HTTPS (TLS) and basic authentication. This project includes configuration for SSL/TLS certificates and user authentication to ensure your application is protected and accessible only to authorized users.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published