From 7bf349340a3dfc81e42b2ab592ec76b076f406da Mon Sep 17 00:00:00 2001 From: Florian THIERRY Date: Fri, 13 Jun 2025 23:34:26 +0200 Subject: [PATCH] Initial commit. --- .htpasswd | 1 + README.md | 24 ++++++++++++++++++++++++ docker-compose.yml | 10 ++++++++++ nginx.conf | 19 +++++++++++++++++++ secret-file.txt | 1 + 5 files changed, 55 insertions(+) create mode 100644 .htpasswd create mode 100644 README.md create mode 100644 docker-compose.yml create mode 100644 nginx.conf create mode 100644 secret-file.txt diff --git a/.htpasswd b/.htpasswd new file mode 100644 index 0000000..a748a0a --- /dev/null +++ b/.htpasswd @@ -0,0 +1 @@ +myuser:$apr1$D8La/DaF$WwoLhqkuveOukt8EcVEzr1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..8541ccf --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Generate user-password tuple +Install utility tool: +```bash +sudo apt install apache2-utils +``` + +Generate tuple when file `.htpasswd` does not exist yet: +```bash +htpasswd -c ./.htpasswd myuser +# Then type password twice +``` + +Generate tuple when file `.htpasswd` already exists: +```bash +htpasswd ./.htpasswd myuser +# Then type password twice +``` +# Launch server +```bash +docker compose up +``` + +## Access to secret file +[http://localhost:50080/secret-file.txt](http://localhost:50080/secret-file.txt) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..85b3585 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +services: + nginx: + image: nginx:latest + container_name: nginx_with_auth + ports: + - "50080:80" + volumes: + - ./secret-file.txt:/app/secret-file.txt:ro + - ./nginx.conf:/etc/nginx/nginx.conf:ro + - ./.htpasswd:/etc/nginx/.htpasswd:ro \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..7dd3afd --- /dev/null +++ b/nginx.conf @@ -0,0 +1,19 @@ +events { + worker_connections 1024; +} + +http { + server { + listen 80; + server_name votre_domaine.com; + + location /secret-file.txt { + auth_basic "Accès restreint"; + auth_basic_user_file /etc/nginx/.htpasswd; + + # Autres directives pour servir votre fichier + # Par exemple : + alias /app/secret-file.txt; + } + } +} \ No newline at end of file diff --git a/secret-file.txt b/secret-file.txt new file mode 100644 index 0000000..6769dd6 --- /dev/null +++ b/secret-file.txt @@ -0,0 +1 @@ +Hello world! \ No newline at end of file