diff --git a/Dockerfile b/Dockerfile index decfc0d..089eb76 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ FROM nginx:alpine + COPY ./public /var/www/html - -# Literally copy nginx.conf file from the Dockerfile directory into /etc/nginx/conf.d/default.conf of the container COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80 diff --git a/README.md b/README.md index a16abca..406a548 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,51 @@ Cette branche à pour but de conteneurisé un site HUGO compilé avec un server NGINX. La configuration pour le NGINX reverse proxy en front se trouve dans le dossir nginx-proxy. -## CONFIG +## UTILISATION: +Pour l'utiliser avec un autre site Hugo, copier simplement la Dockerfile ou le docker-compose.yml +ainsi que les dossiers nginx-docker et nginx-proxy à la racine du projet Hugo (à côté du config.toml) +et éxécuter la commande pour construire le site: + +```bash +hugo +``` + +Un dossier public s'est créé avec les fichiers statiques du site, il faut maintenant configurer +les Nginx (le proxy et celui dans l'image Docker: + +## CONFIGURATION: + +Editer le fichier de configuration ```bash nano nginx-proxy/nginx.conf ``` -/\ Attention, le nom de domaine est à configuré dans le proxy NGINX ! +/\ Attention, le nom de domaine (ici exemple.com) est à configuré dans le proxy NGINX ! +Une fois tout bien renseigné -### Pour le HTTPS: +Redémarrer NGINX: + +```bash +sudo systemctl restart nginx +``` + +## DEMARRER L'IMAGE: + +### VIA DOCKER + +```bash +docker build -t hugo/hugo-site . +docker run -d -p 6666:80 --name hugo-site hugo/hugo-site +``` + +### VIA DOCKER-COMPOSE + +```bash +docker-compose up -d +``` + +### HTTPS: Via Certbot: ```bash @@ -26,30 +62,8 @@ le nom des certificats en fonction du nom de domaine: #ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; #ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ``` +Créer une redirection vers le HTTPS dans le bloc server HTTP: -Redémarrer NGINX: - -```bash -sudo systemctl restart nginx ``` - -## BUILD - -```bash -hugo +return 301 https://$host$request_uri; ``` - -## START - -### DOCKER - -```bash -docker build -t hugo/hugo-site . -docker run -d -p 6666:80 --name hugo-site hugo/hugo-site -``` - -### DOCKER-COMPOSE - -```bash -docker-compose up -d -``` diff --git a/nginx-proxy/nginx-proxy.conf b/nginx-proxy/nginx-proxy.conf index 09f765b..8c053a1 100644 --- a/nginx-proxy/nginx-proxy.conf +++ b/nginx-proxy/nginx-proxy.conf @@ -8,10 +8,25 @@ server { client_max_body_size 64M; # Redirection HTTP -> HTTPS - return 301 https://$host$request_uri; + #return 301 https://$host$request_uri; + location / { + proxy_buffering off; + proxy_redirect off; + 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-Host $server_name; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_pass http://127.0.0.1:6666; + } } + # Nécessaire pour les redirections internes à Hugo + location /feed { + return 302 https://example.com/index.xml; + } + # HTTPS server{ listen 443 ssl http2; @@ -30,7 +45,7 @@ server{ proxy_pass http://127.0.0.1:6666; } - # Nécessaire pour les redirections inetrnes à Hugo + # Nécessaire pour les redirections internes à Hugo location /feed { return 302 https://example.com/index.xml; } @@ -41,5 +56,4 @@ server{ access_log /var/log/nginx/hugo_access.log; error_log /var/log/nginx/hugo_error.log; - }