From d01cf640440a2ca048e07f9c1039fdb5580db467 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Thu, 22 Oct 2026 23:14:15 +0300 Subject: feat: add personal site --- provision.yml | 2 + roles/personal/tasks/main.yml | 39 ++++++++++++++++++ roles/personal/templates/htpasswd.j2 | 9 +++++ roles/personal/templates/nginx.conf.j2 | 74 ++++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 roles/personal/tasks/main.yml create mode 100644 roles/personal/templates/htpasswd.j2 create mode 100644 roles/personal/templates/nginx.conf.j2 diff --git a/provision.yml b/provision.yml index 00ae2fd..ac181c2 100644 --- a/provision.yml +++ b/provision.yml @@ -30,3 +30,5 @@ - role: fail2ban - role: nginx + + - role: personal diff --git a/roles/personal/tasks/main.yml b/roles/personal/tasks/main.yml new file mode 100644 index 0000000..6a9b7c7 --- /dev/null +++ b/roles/personal/tasks/main.yml @@ -0,0 +1,39 @@ +--- +- block: + - name: Ensure personal web root exists + ansible.builtin.file: + path: /srv/http/michalec.dev + state: directory + owner: cmmm + group: www-data + mode: '0775' + + - name: Ensure nginx site modular directory exists + ansible.builtin.file: + path: /etc/nginx/http.d/michalec.dev.d + state: directory + owner: root + group: root + mode: '0755' + + - name: Deploy personal nginx site configuration + ansible.builtin.template: + src: nginx.conf.j2 + dest: /etc/nginx/http.d/personal.conf + owner: root + group: root + mode: '0444' + validate: nginx-validate %s /etc/nginx/http.d/personal.conf + notify: Reload nginx + + - name: Deploy personal nginx htpasswd + ansible.builtin.template: + src: htpasswd.j2 + dest: /etc/nginx/htpasswd + owner: root + group: nginx + mode: '0440' + notify: Reload nginx + + tags: + - personal diff --git a/roles/personal/templates/htpasswd.j2 b/roles/personal/templates/htpasswd.j2 new file mode 100644 index 0000000..657d165 --- /dev/null +++ b/roles/personal/templates/htpasswd.j2 @@ -0,0 +1,9 @@ +$ANSIBLE_VAULT;1.1;AES256 +65393532343134393463373936346137323139636165363530323337636631613632323563316536 +6464356539343231643763653562303734666566653736630a373566623364626365373939393136 +38643961616536393664353563623032376663363430333439393363663838303838376363653731 +3462323538623962630a393661626161333464323139333265626236396537366266663766663635 +61383562383562633638643239643230336164663030623261363934363865373630633563656335 +37633665373265666339303065613737383431353736613034393264303964323663393162623335 +38343062346464653263306566336232616638383332343433393630343934636232376566313138 +62303331633538663365 diff --git a/roles/personal/templates/nginx.conf.j2 b/roles/personal/templates/nginx.conf.j2 new file mode 100644 index 0000000..fdb869b --- /dev/null +++ b/roles/personal/templates/nginx.conf.j2 @@ -0,0 +1,74 @@ +# -*- Nginx -*- +# {{ ansible_managed }} + +server { + listen 80; + listen [::]:80; + server_name michalec.dev + www.michalec.dev + git.michalec.dev + lists.michalec.dev; + + location ^~ /.well-known/acme-challenge/ { + root /var/www/acme; + } + + location / { + return 307 https://$host$request_uri; + } +} + +server { + server_name michalec.dev + www.michalec.dev; + + listen unix:/var/run/nginx/http.sock; + listen 443 ssl; + listen [::]:443 ssl; + listen 443 quic reuseport; + listen [::]:443 quic reuseport; + + http2 on; + http3 on; + + add_header Alt-Svc 'h3=":443"; ma=86400'; + + ssl_certificate /etc/ssl/michalec.dev.fullchain.pem; + ssl_certificate_key /etc/ssl/private/michalec.dev.key; + ssl_protocols TLSv1.2 TLSv1.3; + + root /srv/http/michalec.dev; + index index.html; + + location /private/ { + auth_basic "private"; + auth_basic_user_file /etc/nginx/htpasswd; + + try_files $uri $uri/ =404; + + location = /private/status { + stub_status; + } + } + + location /files/ { + alias /srv/http/michalec.dev/; + index nonexistent; + autoindex on; + } + location /files/private/ { + alias /srv/http/michalec.dev/private/; + index nonexistent; + autoindex on; + + auth_basic "private"; + auth_basic_user_file /etc/nginx/htpasswd; + } + + location /en/ { try_files $uri $uri/ =404; } + location /ru/ { try_files $uri $uri/ =404; } + location /sk/ { try_files $uri $uri/ =404; } + location / { try_files $uri /en$uri /en$uri/ =404; } + + include /etc/nginx/http.d/michalec.dev.d/*.conf; +} -- cgit v1.3.1