From 75347648bca41a1c0b93c379f33e5f70941c6a9e Mon Sep 17 00:00:00 2001 From: Urban Date: Sun, 12 Oct 2025 18:41:02 +0200 Subject: [PATCH] initial commit --- Dockerfile | 9 ++++ docker-compose.yml | 27 ++++++++++ nginx-conf/default.conf | 52 +++++++++++++++++++ start.sh | 14 +++++ .../f31066df9cf2367b65a26ce81f805df3.txt | 0 static-html-directory/index.html | 5 ++ 6 files changed, 107 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx-conf/default.conf create mode 100755 start.sh create mode 100644 static-html-directory/f31066df9cf2367b65a26ce81f805df3.txt create mode 100644 static-html-directory/index.html diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4cfdbb6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +#FROM nginx +#COPY static-html-directory /usr/share/nginx/html +FROM nginx:stable-alpine + +# Copy static site (optional, if you want to serve anything at / directly) +COPY static-html-directory /usr/share/nginx/html + +# Replace all default confs with ours +COPY nginx-conf/default.conf /etc/nginx/conf.d/default.conf diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..cfd7118 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: "3.9" + +services: + nginx: + container_name: mynginx + build: + context: . # mappen där Dockerfile finns + dockerfile: Dockerfile # din Dockerfile (från frågan) + ports: + - "80:80" # exponerar HTTP till HAProxy + restart: unless-stopped + networks: + - web + - infra-net + healthcheck: + test: ["CMD-SHELL", "wget -q -O- http://localhost/health || exit 1"] + interval: 10s + timeout: 3s + retries: 5 + +networks: + web: + external: true # använder redan befintligt nät + name: web + infra-net: + external: true # använder redan befintligt nät + name: infra-net diff --git a/nginx-conf/default.conf b/nginx-conf/default.conf new file mode 100644 index 0000000..c2a78e4 --- /dev/null +++ b/nginx-conf/default.conf @@ -0,0 +1,52 @@ +server { + listen 80; + server_name rubble.se localhost; + + # (valfritt) statiskt default + root /usr/share/nginx/html; + index index.html; + + # OBS: låt / flöda sist, annars kan try_files vinna över prefixen + + # ---- Flappy (som tidigare) ---- + location ^~ /flappy/ { + proxy_pass http://flappy/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + rewrite ^/flappy(/.*)$ $1 break; + } + location = /flappy { return 301 /flappy/; } + + # ---- HemHub API under /hemhub ---- + location ^~ /hemhub/ { + # Viktigt: denna fångar även /hemhub/auth/, så vi behöver en mer specifik block nedan + proxy_pass http://hemhub-api:8080/; # trailing slash => strippar /hemhub/ + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + proxy_redirect off; + } + + # ---- Keycloak under /hemhub/auth ---- + # Mer specifik => placera DENNA FÖRE /hemhub/ eller använd ^~ (gör vi här) + location ^~ /hemhub/auth/ { + proxy_pass http://kc-main:8080/; # trailing slash => strippar /hemhub/auth/ + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + proxy_redirect off; + } + + # ---- Health ---- + location = /health { + return 200 "ok\n"; + add_header Content-Type text/plain; + } + + # ---- Default root sist (så att prefix-blocken alltid vinner) ---- + location / { + try_files $uri $uri/ =404; + } +} diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..03cad49 --- /dev/null +++ b/start.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +#docker run --detach \ +# -p 81:80 \ +# --name nginx \ +# --restart unless-stopped \ +# urmo/nginx:latest + +docker run -d \ + --name mysite-nginx \ + --network web \ + -p 80:80 \ + --restart unless-stopped \ + nginx diff --git a/static-html-directory/f31066df9cf2367b65a26ce81f805df3.txt b/static-html-directory/f31066df9cf2367b65a26ce81f805df3.txt new file mode 100644 index 0000000..e69de29 diff --git a/static-html-directory/index.html b/static-html-directory/index.html new file mode 100644 index 0000000..3088255 --- /dev/null +++ b/static-html-directory/index.html @@ -0,0 +1,5 @@ + + +

Here be dragons

+ +