mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 20:36:21 -05:00
Replace nginx with Caddy for TLS termination and reverse proxying.
- Replace nginx with Caddy as the web server for both Docker and native (RPi/Debian) deployments. Caddy handles HTTPS termination, reverse proxying to all services (API, React app, Controller, Kiwix, Help, Map), and serves the media/download file browsers. - Generate a Root CA and signed leaf certificates for HTTPS. The Root CA uses Name Constraints to restrict signing to local addresses only (.local, localhost, and RFC 1918 private IP ranges), mitigating MITM risk if the CA key is compromised. - Add an HTTP landing page that guides users through one-time CA certificate installation on iOS, Android, macOS, Windows, Linux, and Firefox, with auto-redirect when the cert is already trusted. - Add trailing-slash redirects for /controller, /docs, /media, and /download so bare paths don't fall through to the React catch-all. - Add a Root CA download link on the Settings page under Configs. - Update help.sh diagnostics for IPv6 listener detection and HTTP/2 status codes. - Remove all nginx config files and the https_proxy Docker container. - Bump wrolpi-help submodule with certificate documentation.
This commit is contained in:
parent
dd270b37dc
commit
fbb71e012d
43 changed files with 881 additions and 583 deletions
119
docker/web/Caddyfile
Normal file
119
docker/web/Caddyfile
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
# Caddy config for WROLPi services (Docker).
|
||||
|
||||
{
|
||||
# No ACME - WROLPi is designed for offline use.
|
||||
auto_https disable_redirects
|
||||
}
|
||||
|
||||
:80 {
|
||||
handle / {
|
||||
root * /var/www
|
||||
rewrite * /landing.html
|
||||
file_server
|
||||
}
|
||||
handle /ca.crt {
|
||||
root * /opt/media/config/ssl
|
||||
header Content-Type "application/x-x509-ca-cert"
|
||||
header Content-Disposition "attachment; filename=\"wrolpi-ca.crt\""
|
||||
file_server
|
||||
}
|
||||
handle {
|
||||
redir https://{host}:8443{uri} permanent
|
||||
}
|
||||
}
|
||||
|
||||
:443 {
|
||||
tls /etc/ssl/caddy/cert.crt /etc/ssl/caddy/cert.key
|
||||
|
||||
handle /favicon.ico {
|
||||
root * /etc/caddy
|
||||
rewrite * /favicon.ico
|
||||
file_server
|
||||
}
|
||||
|
||||
handle /apple-touch-icon.png {
|
||||
root * /etc/caddy
|
||||
rewrite * /icon.png
|
||||
file_server
|
||||
}
|
||||
|
||||
# WebSocket for React dev server.
|
||||
handle /ws {
|
||||
reverse_proxy app:3000
|
||||
}
|
||||
|
||||
# Controller - system management API and UI.
|
||||
handle_path /controller/* {
|
||||
reverse_proxy controller:8087
|
||||
}
|
||||
handle /controller {
|
||||
redir * /controller/ 301
|
||||
}
|
||||
|
||||
# Main API.
|
||||
handle /api/* {
|
||||
reverse_proxy api:8081
|
||||
}
|
||||
|
||||
# API docs.
|
||||
handle /docs/* {
|
||||
reverse_proxy api:8081
|
||||
}
|
||||
handle /docs {
|
||||
redir * /docs/ 301
|
||||
}
|
||||
|
||||
# Static media files with directory browsing.
|
||||
handle_path /media/* {
|
||||
root * /opt/media
|
||||
file_server browse
|
||||
}
|
||||
handle /media {
|
||||
redir * /media/ 301
|
||||
}
|
||||
|
||||
# Downloads with Content-Disposition header.
|
||||
handle_path /download/* {
|
||||
root * /opt/media
|
||||
header Content-Disposition "attachment"
|
||||
file_server browse
|
||||
}
|
||||
handle /download {
|
||||
redir * /download/ 301
|
||||
}
|
||||
|
||||
# React app with fallback to Controller.
|
||||
handle {
|
||||
reverse_proxy app:3000 {
|
||||
@bad status 502 503 504
|
||||
handle_response @bad {
|
||||
header Location /controller/?fallback=true
|
||||
respond "" 302
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Kiwix HTTPS proxy (replaces zim_https container).
|
||||
:8085 {
|
||||
tls /etc/ssl/caddy/cert.crt /etc/ssl/caddy/cert.key
|
||||
header ?Access-Control-Allow-Origin "*"
|
||||
header ?Access-Control-Allow-Methods "GET, OPTIONS"
|
||||
reverse_proxy zim:80
|
||||
}
|
||||
|
||||
# Help HTTPS proxy (replaces help_https container).
|
||||
:8086 {
|
||||
tls /etc/ssl/caddy/cert.crt /etc/ssl/caddy/cert.key
|
||||
header ?Access-Control-Allow-Origin "*"
|
||||
header ?Access-Control-Allow-Methods "GET, OPTIONS"
|
||||
reverse_proxy help:80
|
||||
}
|
||||
|
||||
# Map HTTPS proxy (replaces map_https container).
|
||||
:8084 {
|
||||
tls /etc/ssl/caddy/cert.crt /etc/ssl/caddy/cert.key
|
||||
header ?Access-Control-Allow-Origin "*"
|
||||
header ?Access-Control-Allow-Methods "GET, OPTIONS"
|
||||
reverse_proxy map:80
|
||||
}
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
FROM nginx:latest
|
||||
FROM caddy:latest
|
||||
|
||||
# Create a self-signed cert and key pair for HTTPS.
|
||||
RUN openssl genrsa -out /cert.key 2048
|
||||
RUN openssl req -new -x509 -nodes -key /cert.key -out /cert.crt -days 3650 \
|
||||
-subj "/C=US/ST=State/L=City/O=Org/OU=WROLPi/CN=wrolpi.local"
|
||||
RUN chmod 777 /cert.key /cert.crt
|
||||
RUN apk add --no-cache openssl bash
|
||||
|
||||
RUN rm /etc/nginx/conf.d/default.conf
|
||||
COPY docker/web/nginx.dev.conf /etc/nginx/nginx.conf
|
||||
COPY docker/web/wrolpi.dev.conf /etc/nginx/conf.d/wrolpi.conf
|
||||
# Copy scripts and static files.
|
||||
COPY docker/web/Caddyfile /etc/caddy/Caddyfile
|
||||
COPY docker/web/entrypoint.sh /entrypoint.sh
|
||||
COPY scripts/generate_certificates.sh /opt/wrolpi/scripts/generate_certificates.sh
|
||||
COPY etc/raspberrypios/landing.html /var/www/landing.html
|
||||
|
||||
RUN chmod +x /entrypoint.sh /opt/wrolpi/scripts/generate_certificates.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
|
|
|||
11
docker/web/entrypoint.sh
Normal file
11
docker/web/entrypoint.sh
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
export MEDIA_DIRECTORY="${MEDIA_DIRECTORY:-/opt/media}"
|
||||
export CERT_DIR="/etc/ssl/caddy"
|
||||
|
||||
# EXTRA_SANS can be set to include additional SANs in the leaf certificate.
|
||||
# This is needed in Docker because the container cannot discover the host's
|
||||
# real LAN IP. Example: EXTRA_SANS=IP:10.0.0.5,DNS:myhost.local
|
||||
export EXTRA_SANS="${EXTRA_SANS:-}"
|
||||
|
||||
/opt/wrolpi/scripts/generate_certificates.sh
|
||||
exec caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
events {
|
||||
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
client_max_body_size 0;
|
||||
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
'' close;
|
||||
}
|
||||
charset utf-8;
|
||||
|
||||
include mime.types;
|
||||
types {
|
||||
# Custom types for ebooks.
|
||||
application/x-mobipocket-ebook mobi;
|
||||
application/epub+zip epub;
|
||||
# Configs
|
||||
text/yaml yaml yml;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name _; # Default server for requests without "Host" header
|
||||
|
||||
location / {
|
||||
return 301 https://$host:8443$request_uri;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
proxy_pass_header Host;
|
||||
|
||||
# Self-signed cert from Dockerfile build.
|
||||
ssl_certificate /cert.crt;
|
||||
ssl_certificate_key /cert.key;
|
||||
|
||||
include /etc/nginx/conf.d/*;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
# Nginx config for the WROLPi services.
|
||||
|
||||
#
|
||||
# App
|
||||
#
|
||||
|
||||
location /favicon.ico {
|
||||
alias /etc/nginx/favicon.ico;
|
||||
}
|
||||
|
||||
location /apple-touch-icon.png {
|
||||
alias /etc/nginx/icon.png;
|
||||
}
|
||||
|
||||
location / {
|
||||
# React APP with Controller fallback
|
||||
proxy_pass http://app:3000;
|
||||
proxy_intercept_errors on;
|
||||
error_page 502 503 504 = @react_fallback;
|
||||
rewrite $1 break;
|
||||
}
|
||||
|
||||
location @react_fallback {
|
||||
return 302 /controller/?fallback=true;
|
||||
}
|
||||
|
||||
location /ws {
|
||||
proxy_pass http://app:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
}
|
||||
|
||||
#
|
||||
# Controller - system management API and UI
|
||||
# All Controller endpoints are under /controller/*
|
||||
#
|
||||
location /controller {
|
||||
rewrite ^/controller(.*)$ $1 break;
|
||||
proxy_pass http://controller:8087;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
}
|
||||
|
||||
#
|
||||
# Main API - handled by the API service (port 8081)
|
||||
#
|
||||
|
||||
location /api {
|
||||
proxy_pass http://api:8081;
|
||||
rewrite /^api(.*)$ $1 break;
|
||||
}
|
||||
|
||||
location /docs {
|
||||
proxy_pass http://api:8081;
|
||||
rewrite /^docs(.*)$ $1 break;
|
||||
}
|
||||
|
||||
location /media {
|
||||
# The media files mounted in the docker volume
|
||||
sendfile on;
|
||||
sendfile_max_chunk 1m;
|
||||
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
|
||||
autoindex on;
|
||||
autoindex_exact_size off;
|
||||
alias /opt/media;
|
||||
}
|
||||
|
||||
location /download {
|
||||
# Assume any request here is to download a file from the media directory.
|
||||
if ( $request_filename ~ '^.*/(.+)$' ) {
|
||||
# Always include the filename for downloads.
|
||||
add_header Content-Disposition 'attachment; filename="$1"';
|
||||
}
|
||||
|
||||
sendfile on;
|
||||
sendfile_max_chunk 1m;
|
||||
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
|
||||
autoindex on;
|
||||
autoindex_exact_size off;
|
||||
alias /opt/media;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue