Personal Activity Index - Reverse Proxy Configurations#
This directory contains example reverse proxy configurations for deploying the Personal Activity Index HTTP server behind nginx or Caddy.
Quick Start#
Option 1: nginx#
macOS#
-
Install nginx:
brew install nginx -
Copy the configuration:
# For localhost testing cp nginx.conf /opt/homebrew/etc/nginx/servers/pai.conf # Or symlink to keep it in sync ln -s $(pwd)/nginx.conf /opt/homebrew/etc/nginx/servers/pai.conf -
Start the pai server:
pai serve -a 127.0.0.1:8080 -
Start nginx:
brew services start nginx -
Access at http://localhost
Linux#
-
Install nginx:
# Debian/Ubuntu sudo apt install nginx # RHEL/Fedora sudo dnf install nginx -
Copy the configuration:
sudo cp nginx.conf /etc/nginx/sites-available/pai sudo ln -s /etc/nginx/sites-available/pai /etc/nginx/sites-enabled/ -
Start the pai server:
pai serve -a 127.0.0.1:8080 -
Test and reload nginx:
sudo nginx -t sudo systemctl reload nginx -
Access at http://localhost
Option 2: Caddy#
macOS#
-
Install Caddy:
brew install caddy -
Copy the Caddyfile:
cp Caddyfile /opt/homebrew/etc/Caddyfile -
Start the pai server:
pai serve -a 127.0.0.1:8080 -
Start Caddy:
brew services start caddy -
Access at http://localhost
Linux#
-
Install Caddy:
# See https://caddyserver.com/docs/install # Debian/Ubuntu sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list sudo apt update sudo apt install caddy -
Copy the Caddyfile:
sudo cp Caddyfile /etc/caddy/Caddyfile -
Start the pai server:
pai serve -a 127.0.0.1:8080 -
Reload Caddy:
sudo systemctl reload caddy -
Access at http://localhost
Production Deployment with Custom Domain#
nginx with SSL#
-
Edit
nginx.confand replacelocalhostwith your domain (e.g.,pai.example.com) -
Obtain SSL certificates using certbot:
# macOS brew install certbot # Linux sudo apt install certbot python3-certbot-nginx # Debian/Ubuntu sudo dnf install certbot python3-certbot-nginx # RHEL/Fedora -
Get certificates:
sudo certbot --nginx -d pai.example.com -
Certbot will automatically update your nginx configuration with SSL settings
-
Set up auto-renewal:
# Test renewal sudo certbot renew --dry-run # On Linux, certbot sets up a systemd timer automatically # On macOS, add to crontab: sudo crontab -e # Add: 0 0 * * * certbot renew --quiet
Caddy with Custom Domain#
-
Edit
Caddyfileand uncomment the production section -
Replace
pai.example.comwith your actual domain -
Ensure DNS A/AAAA records point to your server
-
Reload Caddy:
sudo systemctl reload caddy # Linux brew services restart caddy # macOS
Caddy automatically obtains and renews SSL certificates from Let's Encrypt - no additional configuration needed!
Running pai as a System Service#
macOS (launchd)#
Create /Library/LaunchDaemons/com.pai.server.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.pai.server</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/pai</string>
<string>serve</string>
<string>-a</string>
<string>127.0.0.1:8080</string>
<string>-d</string>
<string>/var/lib/pai/pai.db</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/var/log/pai/stdout.log</string>
<key>StandardErrorPath</key>
<string>/var/log/pai/stderr.log</string>
<key>WorkingDirectory</key>
<string>/var/lib/pai</string>
</dict>
</plist>
Load the service:
sudo launchctl load /Library/LaunchDaemons/com.pai.server.plist
Linux (systemd)#
Create /etc/systemd/system/pai.service:
[Unit]
Description=Personal Activity Index
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/pai serve -a 127.0.0.1:8080 -d /var/lib/pai/pai.db
Restart=on-failure
RestartSec=5
User=pai
Group=pai
WorkingDirectory=/var/lib/pai
[Install]
WantedBy=multi-user.target
Create the pai user and directories:
sudo useradd -r -s /bin/false pai
sudo mkdir -p /var/lib/pai
sudo chown pai:pai /var/lib/pai
Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable pai
sudo systemctl start pai
Check status:
sudo systemctl status pai
View logs:
sudo journalctl -u pai -f
Testing#
Verify the proxy is working:
# Health check
curl http://localhost/status
# API endpoint
curl http://localhost/api/feed?limit=5
# Specific item
curl http://localhost/api/item/some-item-id