M6: serve and export modes, packaging

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
lucioandClaude Opus 5.5 committed 2026-11-04 04:58:48 -08:00
1 parent 45105d292f
commit 00ee2a6d12
29 files changed
+1294 -75

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
photos.luciochen.com {
root * /var/lib/luphoto/site/current
@hotlink {
path /t/*
header Referer *
not header_regexp Referer ^https?://photos\.luciochen\.com(:[0-9]+)?(/|$)
}
respond @hotlink 403
@hidden path */.* *.gz
respond @hidden 404
@immutable path /t/* /og/* /assets/*
header @immutable Cache-Control "public, max-age=31536000, immutable"
@short not path /t/* /og/* /assets/*
header @short Cache-Control "public, max-age=60"
header {
Content-Security-Policy "default-src 'self'; img-src 'self' blob: data:; font-src 'self'; worker-src 'self'; frame-ancestors 'none'"
X-Content-Type-Options nosniff
Referrer-Policy strict-origin-when-cross-origin
-Server
}
@methods not method GET HEAD
respond @methods 405
file_server {
precompressed gzip
}
}
+3
View File
@@ -0,0 +1,3 @@
photos.luciochen.com {
reverse_proxy 127.0.0.1:8080
}
+23
View File
@@ -0,0 +1,23 @@
# Installing LuPhoto from the tarball
For distributions without the `.deb`. You need libvips 8.12 or newer with its command-line tools (`vips`, `vipsheader`), for example `dnf install vips-tools` or `pacman -S libvips`.
```sh
tar xzf luphoto_<version>_linux_<arch>.tar.gz
cd luphoto_<version>_linux_<arch>
sudo install -m 0755 luphoto /usr/bin/luphoto
sudo install -d /etc/luphoto
sudo install -m 0644 config.toml /etc/luphoto/config.toml
sudo install -m 0644 luphoto.service /etc/systemd/system/luphoto.service
sudo groupadd --system luphoto
sudo useradd --system --gid luphoto --home-dir /var/lib/luphoto --no-create-home --shell /usr/sbin/nologin luphoto
sudo groupadd --system luphoto-upload
sudo install -d -m 2775 -o root -g luphoto-upload /srv/luphoto/albums
sudo install -d -m 0755 -o luphoto -g luphoto /var/lib/luphoto /var/cache/luphoto
sudo systemctl daemon-reload
sudo systemctl enable --now luphoto
```
Add uploaders to the `luphoto-upload` group. Edit `/etc/luphoto/config.toml`, then `sudo systemctl reload luphoto`. Web server examples are in `examples/`.
+10
View File
@@ -0,0 +1,10 @@
# Cloudflare
Run the site behind a Cloudflare Tunnel (`cloudflared.yml` in this folder). In serve mode the tunnel points at LuPhoto on `127.0.0.1:8080`. In export mode it points at Caddy or nginx; give that web server a plain HTTP listener on `127.0.0.1:8080` for the tunnel, for example `http://photos.luciochen.com:8080` in the Caddyfile, or `listen 127.0.0.1:8080;` in nginx.
Cache rules (Caching → Cache Rules), in this order:
1. Tiles, OG images and assets: when the URI path starts with `/t/`, `/og/` or `/assets/`, set *Eligible for cache*, Edge TTL 1 month (or "use cache-control header"), Browser TTL "respect origin". Their names are content-hashed, so they never change.
2. Everything else (HTML, `/a/*`, `index.<build>.json`): Edge TTL 1 minute or "respect origin" (`max-age=60`). Manifests are named after the build, so a new build needs no purge.
Keep "Cache by device type" and query-string variations off. Hotlink protection is done by LuPhoto, Caddy or nginx on `/t/*`; Cloudflare's own Hotlink Protection can stay off, or be enabled for the same hostname.
+8
View File
@@ -0,0 +1,8 @@
tunnel: luphoto
credentials-file: /etc/cloudflared/luphoto.json
ingress:
- hostname: photos.luciochen.com
service: http://127.0.0.1:8080
originRequest:
httpHostHeader: photos.luciochen.com
- service: http_status:404
+34
View File
@@ -0,0 +1,34 @@
[server]
mode = "export"
listen = "127.0.0.1:8080"
base_url = "https://photos.luciochen.com"
[paths]
albums = "/srv/luphoto/albums"
output = "/var/lib/luphoto/site"
cache = "/var/cache/luphoto"
[images]
tile_size = 512
overlap = 1
format = "webp"
quality = { top = 82, mid = 85, low = 88 }
min_levels = 6
seed_px = 48
tile_names = "hashed"
scramble_cells = false
[loading]
budget_ms = 3000
max_dpr = 2.0
concurrency = 6
[build]
watch = true
debounce = "30s"
workers = 2
keep_builds = 3
[protection]
block_context_menu = true
hotlink_allow = ["photos.luciochen.com"]
+41
View File
@@ -0,0 +1,41 @@
[Unit]
Description=LuPhoto photo site (photos.luciochen.com)
Documentation=https://github.com/luciochen233/luphoto
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=luphoto
Group=luphoto
ExecStart=/usr/bin/luphoto -config /etc/luphoto/config.toml run
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=5
TimeoutStopSec=30
Nice=5
UMask=0022
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
PrivateDevices=true
NoNewPrivileges=true
ReadOnlyPaths=/srv/luphoto/albums
ReadWritePaths=/var/lib/luphoto /var/cache/luphoto
CapabilityBoundingSet=
AmbientCapabilities=
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
RestrictNamespaces=true
RestrictRealtime=true
RestrictSUIDSGID=true
LockPersonality=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectKernelLogs=true
ProtectControlGroups=true
ProtectClock=true
ProtectHostname=true
SystemCallArchitectures=native
[Install]
WantedBy=multi-user.target
+48
View File
@@ -0,0 +1,48 @@
name: luphoto
arch: ${GOARCH}
platform: linux
version: ${VERSION}
version_schema: none
section: web
priority: optional
maintainer: Guoliang Chen <[email protected]>
description: |
Static, tiled photo site for photos.luciochen.com.
Reads album folders, cuts photos into 512 px tiles with libvips and
publishes a static site that a browser stitches back together.
homepage: https://photos.luciochen.com
depends:
- libvips-tools
- passwd
contents:
- src: dist/package/luphoto
dst: /usr/bin/luphoto
file_info:
mode: 0755
- src: packaging/config.toml
dst: /etc/luphoto/config.toml
type: config|noreplace
file_info:
mode: 0644
- src: packaging/luphoto.service
dst: /usr/lib/systemd/system/luphoto.service
file_info:
mode: 0644
- src: packaging/Caddyfile
dst: /usr/share/doc/luphoto/examples/Caddyfile
- src: packaging/Caddyfile.serve
dst: /usr/share/doc/luphoto/examples/Caddyfile.serve
- src: packaging/nginx.conf
dst: /usr/share/doc/luphoto/examples/nginx.conf
- src: packaging/nginx.serve.conf
dst: /usr/share/doc/luphoto/examples/nginx.serve.conf
- src: packaging/cloudflared.yml
dst: /usr/share/doc/luphoto/examples/cloudflared.yml
- src: packaging/cloudflare.md
dst: /usr/share/doc/luphoto/cloudflare.md
- src: README.md
dst: /usr/share/doc/luphoto/README.md
scripts:
postinstall: packaging/scripts/postinstall.sh
preremove: packaging/scripts/preremove.sh
postremove: packaging/scripts/postremove.sh
+57
View File
@@ -0,0 +1,57 @@
map $http_referer $luphoto_hotlink {
default 1;
"" 0;
"~^https?://photos\.luciochen\.com(:[0-9]+)?(/|$)" 0;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name photos.luciochen.com;
ssl_certificate /etc/letsencrypt/live/photos.luciochen.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/photos.luciochen.com/privkey.pem;
root /var/lib/luphoto/site/current;
index index.html;
autoindex off;
disable_symlinks off;
gzip_static on;
server_tokens off;
if ($request_method !~ ^(GET|HEAD)$) {
return 405;
}
location ~ (/\.|\.gz$) {
return 404;
}
location /t/ {
if ($luphoto_hotlink) {
return 403;
}
add_header Cache-Control "public, max-age=31536000, immutable" always;
add_header Content-Security-Policy "default-src 'self'; img-src 'self' blob: data:; font-src 'self'; worker-src 'self'; frame-ancestors 'none'" always;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
try_files $uri =404;
}
location ~ ^/(og|assets)/ {
add_header Cache-Control "public, max-age=31536000, immutable" always;
add_header Content-Security-Policy "default-src 'self'; img-src 'self' blob: data:; font-src 'self'; worker-src 'self'; frame-ancestors 'none'" always;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
try_files $uri =404;
}
location / {
add_header Cache-Control "public, max-age=60" always;
add_header Content-Security-Policy "default-src 'self'; img-src 'self' blob: data:; font-src 'self'; worker-src 'self'; frame-ancestors 'none'" always;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
try_files $uri $uri/index.html =404;
}
}
+18
View File
@@ -0,0 +1,18 @@
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name photos.luciochen.com;
ssl_certificate /etc/letsencrypt/live/photos.luciochen.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/photos.luciochen.com/privkey.pem;
server_tokens off;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Connection "";
proxy_buffering on;
}
}
+27
View File
@@ -0,0 +1,27 @@
#!/bin/sh
set -e
if ! getent group luphoto >/dev/null; then
groupadd --system luphoto
fi
if ! getent passwd luphoto >/dev/null; then
useradd --system --gid luphoto --home-dir /var/lib/luphoto --no-create-home --shell /usr/sbin/nologin --comment "LuPhoto" luphoto
fi
if ! getent group luphoto-upload >/dev/null; then
groupadd --system luphoto-upload
fi
usermod -a -G luphoto-upload luphoto
if [ ! -d /srv/luphoto/albums ]; then
install -d -m 0755 -o root -g root /srv/luphoto
install -d -m 2775 -o root -g luphoto-upload /srv/luphoto/albums
fi
install -d -m 0755 -o luphoto -g luphoto /var/lib/luphoto /var/cache/luphoto
if [ -d /run/systemd/system ]; then
systemctl daemon-reload >/dev/null 2>&1 || true
if systemctl is-active --quiet luphoto.service; then
systemctl try-restart luphoto.service >/dev/null 2>&1 || true
fi
fi
exit 0
+10
View File
@@ -0,0 +1,10 @@
#!/bin/sh
set -e
if [ -d /run/systemd/system ]; then
systemctl daemon-reload >/dev/null 2>&1 || true
fi
if [ "$1" = "purge" ]; then
rm -rf /var/cache/luphoto
fi
exit 0
+8
View File
@@ -0,0 +1,8 @@
#!/bin/sh
set -e
if [ -d /run/systemd/system ] && [ "$1" = "remove" ]; then
systemctl stop luphoto.service >/dev/null 2>&1 || true
systemctl disable luphoto.service >/dev/null 2>&1 || true
fi
exit 0