nginx: Add `nginx-serve-volume` service

This service allows for easy serving of static content in a volume,
typically HTML files in directory structures mapping to the navigation
structure for the content served.
This commit is contained in:
Alex Palaistras 2021-12-06 12:02:52 +00:00
parent 576ded0eee
commit 1effe81ec7
3 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,7 @@
server {
listen 8080;
server_name ${SERVER_NAME};
root ${SERVER_ROOT};
include server.conf;
}

View File

@ -0,0 +1,25 @@
[Unit]
Description=NGINX Web Service for Volume %I
Wants=nginx.service
After=nginx.service
[Service]
Type=notify
NotifyAccess=all
SyslogIdentifier=%N
Restart=on-failure
Environment=PODMAN_SYSTEMD_UNIT=%n
Environment=SERVER_NAME=%p-%i SERVER_ROOT=/srv
Environment=NGINX_CONF=%E/coreos-home-server/nginx/service/%p.conf.template
ExecStartPre=/bin/podman create --replace --name $SERVER_NAME --net internal --sdnotify=conmon \
--volume %i:/srv:z,ro \
localhost/nginx:latest
ExecStartPre=/bin/sh -c "envsubst '$SERVER_NAME $SERVER_ROOT' < ${NGINX_CONF} > /tmp/%i.conf"
ExecStartPre=/bin/sh -c 'podman cp /tmp/%i.conf ${SERVER_NAME}:/etc/nginx/conf.d/%i.conf && rm -f /tmp/%i.conf'
ExecStart=/bin/podman start --attach $SERVER_NAME
ExecStop=/bin/podman stop --ignore --time 10 $SERVER_NAME
ExecStopPost=/bin/podman rm --ignore --force $SERVER_NAME
[Install]
Alias=%i.service
WantedBy=multi-user.target

View File

@ -72,6 +72,16 @@ systemd:
- name: nginx-proxy-http@php.localhost.service
enabled: true
- name: nginx-serve-volume@git-serve.service
enabled: true
- name: nginx-proxy-http@git.localhost.service
enabled: true
dropins:
- name: git-volume-upstream.conf
contents: |
[Service]
Environment=UPSTREAM_HOST=nginx-serve-volume-git-serve UPSTREAM_PORT=8080
- name: nginx-proxy-http@dav.localhost.service
enabled: true
dropins: