This guide will help you host two applications on a single AWS Lightsail instance:
- Pocketbase at:
http://your-ip/orhttps://your-domain/ - Filebrowser at:
http://your-ip/filebrowserorhttps://your-domain/filebrowser
Important Notes:
- Pocketbase is served at the root path for simplest access and starts automatically
- Filebrowser is configured to manage the Pocketbase directory (
/myapps/pocketbase) for easy file management - Filebrowser does NOT start automatically - start it manually with
sudo supervisorctl start filebrowserwhen needed - Filebrowser requires the
--baseurlflag for proper asset loading under/filebrowser - The launch script sets up HTTP; HTTPS is configured by simply adding your domain to the Caddyfile
- SSHGuard is installed and active for SSH brute-force protection (no configuration needed)
- Enhanced network security settings are applied
- File upload size is limited to 10MB (configurable in Caddyfile)
- Pocketbase has a 6-minute (360 seconds) timeout for long-running operations
- Use
btopcommand for system resource monitoring
- Overview
- Quick Start (Automated)
- Manual Installation (Step-by-Step)
- Step 1: Create Your Lightsail Instance
- Step 2: Connect via SSH
- Step 3: Update System and Install Dependencies
- Step 4: Install Caddy
- Step 5: Create Directory Structure
- Step 6: Download and Install Pocketbase
- Step 7: Download and Install Filebrowser
- Step 8: Configure Supervisor for Pocketbase
- Step 9: Configure Supervisor for Filebrowser
- Step 10: Load Supervisor Configurations
- Step 11: Configure Caddy
- Step 12: Reload Caddy
- Step 13: Configure SSH Security
- Step 14: Configure Network Security Settings
- Step 15: Open Firewall Ports
- Enabling HTTPS (After DNS is Configured)
- Supervisor Quick Reference
- Default Credentials
- Directory Structure
- Troubleshooting
- Next Steps
- Complete Launch Script
When creating your Lightsail instance:
- Go to AWS Lightsail Console
- Click Create instance
- Select Linux/Unix platform
- Choose OS Only → Ubuntu 24.04 LTS
- Scroll to Add launch script
- Copy and paste the complete launch script from the end of this guide
- Choose your instance plan (minimum: $5/month)
- Click Create instance
The script will automatically install and configure everything for HTTP. Wait 3-5 minutes after the instance starts.
Quick Check:
- Installation log:
cat /var/log/setup-complete.log - System monitor:
btop(pressqto exit)
Initial Access (HTTP):
- Pocketbase Public Page:
http://YOUR_IP/(sample page: "Under construction...") - Pocketbase Admin:
http://YOUR_IP/_/(login with credentials fromPOCKETBASE_EMAILandPOCKETBASE_PASS) - Filebrowser: Start manually with
sudo supervisorctl start filebrowser, then accesshttp://YOUR_IP/filebrowser(Check/myapps/filebrowser/filebrowser.err.logfor credentials)
After DNS Configuration:
Edit the script variable CUSTOM_DOMAIN=":80" to your domain before launch, or follow the "Enabling HTTPS" section below to secure your site with SSL certificates (just one config change!).
- Go to AWS Lightsail Console
- Click Create instance
- Select:
- Platform: Linux/Unix
- Blueprint: OS Only → Ubuntu 24.04 LTS
- Instance plan: $5/month or higher
- Name your instance (e.g.,
my-apps-server) - Click Create instance
- Wait for the instance to start
- Click on your instance name
- Click Connect using SSH (browser-based terminal)
sudo apt update && sudo apt upgrade -y
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl supervisor unzip sshguard btopcurl -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 -y caddysudo mkdir -p /myapps/pocketbase
sudo mkdir -p /myapps/filebrowsercd /myapps/pocketbase
sudo wget https://github.com/pocketbase/pocketbase/releases/download/v0.31.0/pocketbase_0.31.0_linux_amd64.zip
sudo unzip pocketbase_0.31.0_linux_amd64.zip
sudo rm pocketbase_0.31.0_linux_amd64.zip
sudo chmod +x pocketbaseOptional: Create a superuser now:
cd /myapps/pocketbase
sudo ./pocketbase superuser create [email protected] your-passwordOptional: Create a sample public page:
sudo mkdir -p /myapps/pocketbase/pb_public
sudo bash -c 'cat > /myapps/pocketbase/pb_public/index.html <<EOF
<!DOCTYPE html><html lang="de"><head><meta charset="utf-8"></head><body><h1>Under construction...</h1></body></html>
EOF'This creates a simple page served at the root URL by Pocketbase.
cd /myapps/filebrowser
sudo wget https://github.com/filebrowser/filebrowser/releases/download/v2.44.2/linux-amd64-filebrowser.tar.gz
sudo tar -xzf linux-amd64-filebrowser.tar.gz
sudo rm linux-amd64-filebrowser.tar.gz
sudo chmod +x filebrowsersudo nano /etc/supervisor/conf.d/pocketbase.confPaste this configuration:
[program:pocketbase]
directory=/myapps/pocketbase
command=/myapps/pocketbase/pocketbase serve --http=127.0.0.1:8090
autostart=true
autorestart=true
stderr_logfile=/myapps/pocketbase/pocketbase.err.log
stdout_logfile=/myapps/pocketbase/pocketbase.out.log
logfile_maxbytes=10MB
logfile_backups=5
user=rootSave and exit (Ctrl+X, then Y, then Enter)
sudo nano /etc/supervisor/conf.d/filebrowser.confPaste this configuration:
[program:filebrowser]
directory=/myapps/filebrowser
command=/myapps/filebrowser/filebrowser -r /myapps/pocketbase -a 127.0.0.1 -p 8091 --baseurl /filebrowser
autostart=false
autorestart=true
stderr_logfile=/myapps/filebrowser/filebrowser.err.log
stdout_logfile=/myapps/filebrowser/filebrowser.out.log
logfile_maxbytes=10MB
logfile_backups=5
user=rootNote: Filebrowser is set to autostart=false and must be started manually when needed.
Save and exit (Ctrl+X, then Y, then Enter)
sudo supervisorctl reread
sudo supervisorctl updateThe update command will load the new configurations. Only Pocketbase will start automatically (Filebrowser is set to manual start).
Check status:
sudo supervisorctl statusYou should see:
pocketbase RUNNINGfilebrowser STOPPED(not started by default)
To start Filebrowser manually when needed:
sudo supervisorctl start filebrowserTo stop Filebrowser:
sudo supervisorctl stop filebrowsersudo nano /etc/caddy/CaddyfileReplace the entire content with:
# HTTP-only configuration (for initial setup)
:80 {
# Limit file upload size
request_body {
max_size 10MB
}
# Filebrowser (must come before root)
# Redirect /filebrowser to /filebrowser/ with trailing slash
handle /filebrowser {
redir {path}/ permanent
}
handle /filebrowser/* {
reverse_proxy localhost:8091
}
# Pocketbase at root (catches everything else)
handle {
reverse_proxy localhost:8090 {
transport http {
read_timeout 360s
}
}
}
}Save and exit (Ctrl+X, then Y, then Enter)
sudo systemctl reload caddyCheck Caddy status:
sudo systemctl status caddyConfigure SSH for key-based authentication only:
sudo nano /etc/ssh/sshd_configFind and modify these lines (remove # if commented):
PubkeyAuthentication yes
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM yes
Or use this automated approach:
sudo sed -i 's/^#*PubkeyAuthentication.*/PubkeyAuthentication yes/' /etc/ssh/sshd_config
sudo sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo sed -i 's/^#*ChallengeResponseAuthentication.*/ChallengeResponseAuthentication no/' /etc/ssh/sshd_config
sudo sed -i 's/^#*UsePAM.*/UsePAM yes/' /etc/ssh/sshd_configRestart SSH to apply changes:
sudo systemctl restart sshImportant: After this step, only key-based SSH authentication will work! Make sure you have your SSH keys configured.
Configure kernel network parameters for enhanced security. These settings protect against various network attacks and improve system security.
Note: The automated sed commands below will replace any existing lines containing these parameters with the correct values, ensuring consistency regardless of whether they're commented, uncommented, or have different values.
# Edit sysctl.conf
sudo nano /etc/sysctl.confEnsure these lines exist with these exact values (add them if missing, update them if they have different values):
# IP Spoofing protection
net.ipv4.conf.default.rp_filter=1
net.ipv4.conf.all.rp_filter=1
# Ignore ICMP redirects (prevent MITM attacks)
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.default.accept_redirects=0
# Ignore send redirects (we are not a router)
net.ipv4.conf.all.send_redirects=0
# Log Martians (packets with impossible source addresses)
net.ipv4.conf.all.log_martians=1
Or use this automated approach with sed commands:
# Replace any line containing these parameters with the correct values
# This ensures consistency regardless of existing comments or values
# Enable IP Spoofing protection (reverse path filtering)
sudo sed -i '/net\.ipv4\.conf\.default\.rp_filter/c\net.ipv4.conf.default.rp_filter=1' /etc/sysctl.conf
sudo sed -i '/net\.ipv4\.conf\.all\.rp_filter/c\net.ipv4.conf.all.rp_filter=1' /etc/sysctl.conf
# Disable ICMP redirects (prevent MITM attacks)
sudo sed -i '/net\.ipv4\.conf\.all\.accept_redirects/c\net.ipv4.conf.all.accept_redirects=0' /etc/sysctl.conf
sudo sed -i '/net\.ipv4\.conf\.default\.accept_redirects/c\net.ipv4.conf.default.accept_redirects=0' /etc/sysctl.conf
# Disable sending ICMP redirects (we're not a router)
sudo sed -i '/net\.ipv4\.conf\.all\.send_redirects/c\net.ipv4.conf.all.send_redirects=0' /etc/sysctl.conf
# Enable logging of Martian packets (impossible source addresses)
sudo sed -i '/net\.ipv4\.conf\.all\.log_martians/c\net.ipv4.conf.all.log_martians=1' /etc/sysctl.confApply the changes:
# Apply new settings (will display all applied settings)
sudo sysctl -p- Go to your Lightsail instance in AWS Console
- Click on the Networking tab
- Under IPv4 Firewall, ensure these ports are open:
- SSH (TCP 22) - (I choose => Restricted to: Lightsail browser SSH/RDP Only)
- HTTP (TCP 80) - Any IPv4 address
- HTTPS (TCP 443) - Any IPv4 address
- Click Save if you made any changes
Once your domain is pointing to your instance (after creating an A record pointing to your static IP):
sudo nano /etc/caddy/CaddyfileReplace :80 with your domain (e.g., sub.domain.ext):
sub.domain.ext {
# Limit file upload size
request_body {
max_size 10MB
}
# Filebrowser configuration...
# Pocketbase configuration...
}Save and reload:
sudo systemctl reload caddyCaddy will automatically:
- Obtain SSL certificates from Let's Encrypt
- Configure HTTPS on port 443
- Redirect HTTP to HTTPS
- Auto-renew certificates
# Check status
sudo supervisorctl status
# Start applications
sudo supervisorctl start pocketbase
sudo supervisorctl start filebrowser
# Stop applications
sudo supervisorctl stop pocketbase
sudo supervisorctl stop filebrowser
# Restart applications
sudo supervisorctl restart pocketbase
sudo supervisorctl restart filebrowser
# View logs
sudo tail -f /myapps/pocketbase/pocketbase.err.log
sudo tail -f /myapps/filebrowser/filebrowser.err.logPocketbase Admin:
- URL:
http://YOUR_IP/_/orhttps://YOUR_DOMAIN/_/ - Email: Set via
POCKETBASE_EMAILin launch script (or created manually) - Password: Set via
POCKETBASE_PASSin launch script (or created manually)
Filebrowser:
- URL:
http://YOUR_IP/filebrowserorhttps://YOUR_DOMAIN/filebrowser - Credentials are shown in:
/myapps/filebrowser/filebrowser.err.log
After installation, your directory structure will look like:
/myapps/
├── pocketbase/
│ ├── pocketbase (executable)
│ ├── pb_data/
│ ├── pb_public/
│ │ └── index.html (sample page)
│ ├── pocketbase.err.log
│ └── pocketbase.out.log
└── filebrowser/
├── filebrowser (executable)
├── filebrowser.db
├── filebrowser.out.log
└── filebrowser.err.log
Note: Filebrowser is configured to show and manage only the /myapps/pocketbase directory, giving you easy access to all Pocketbase files through the web interface.
sudo supervisorctl status
sudo tail -f /myapps/pocketbase/pocketbase.err.log
sudo tail -f /myapps/filebrowser/filebrowser.err.log- Check firewall rules in Lightsail (port 80 and 443 must be open)
- Check Caddy status:
sudo systemctl status caddy - Check Caddy logs:
sudo journalctl -u caddy -n 50
Filebrowser doesn't start automatically. You must start it manually:
sudo supervisorctl start filebrowserThen check if it's running:
sudo supervisorctl status filebrowserThis means the --baseurl /filebrowser flag is missing. Fix it:
sudo nano /etc/supervisor/conf.d/filebrowser.confEnsure the command line includes -r /myapps/pocketbase and --baseurl /filebrowser, then:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl restart filebrowser- Make sure to access:
http://YOUR_IP/_/(note the trailing slash and underscore) - Check that Pocketbase is running:
sudo supervisorctl status pocketbase
- Make sure port 443 is open in your Lightsail firewall
- Ensure your domain is pointing to your instance:
nslookup <sub.domain.ext> - Check Caddy logs:
sudo journalctl -u caddy -n 100 - Remember: DNS must be configured and propagated BEFORE Caddy can obtain a certificate
- If you configured the domain in the Caddyfile before DNS was ready, just wait for DNS propagation then run
sudo systemctl reload caddy
- Your domain DNS is not configured correctly
- Wait a few minutes for DNS propagation
- Verify:
nslookup <sub.domain.ext>returns your instance IP
- Check for typos in domain names in the Caddyfile
- Validate config:
caddy validate --config /etc/caddy/Caddyfile - Check Caddy logs:
sudo journalctl -u caddy -n 50
Recommended production workflow:
- Customize launch script: Set
POCKETBASE_EMAILandPOCKETBASE_PASSto secure credentials - Launch with HTTP: Use
CUSTOM_DOMAIN=":80"in the launch script - Verify setup: Test both applications via HTTP and check with
btop - Attach Static IP: Go to Lightsail → Networking → Create and attach static IP
- Configure DNS: Point your domain to the static IP in Route 53
- Wait for DNS: Verify with
nslookup your-domain.com(1-5 minutes) - Enable HTTPS: Edit
/etc/caddy/Caddyfile, replace:80with your domain, runsudo systemctl reload caddy - Setup backups: Create regular snapshots in Lightsail Console
- Monitor security: Check
/var/log/syslogfor Martian packets and security events
Copy this entire script when creating your Lightsail instance:
#!/bin/bash
# App config
POCKETBASE_VERSION="0.31.0"
POCKETBASE_EMAIL="[email protected]"
POCKETBASE_PASS="12345678"
FILEBROWSER_VERSION="2.44.2"
# To enable HTTPS: replace ":80" with your domain (e.g., "sub.domain.ext")
CUSTOM_DOMAIN=":80"
# Update system
apt update && apt upgrade -y
# Install dependencies
apt install -y debian-keyring debian-archive-keyring apt-transport-https curl supervisor unzip sshguard btop
# Install Caddy
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
apt update
apt install -y caddy
# Create directory structure
mkdir -p /myapps/pocketbase
mkdir -p /myapps/filebrowser
# Download and install Pocketbase
cd /myapps/pocketbase
wget -q "https://github.com/pocketbase/pocketbase/releases/download/v${POCKETBASE_VERSION}/pocketbase_${POCKETBASE_VERSION}_linux_amd64.zip"
unzip -q "pocketbase_${POCKETBASE_VERSION}_linux_amd64.zip"
rm "pocketbase_${POCKETBASE_VERSION}_linux_amd64.zip"
chmod +x pocketbase
# Create Pocketbase superuser
./pocketbase superuser create "${POCKETBASE_EMAIL}" "${POCKETBASE_PASS}"
# Create pb_public directory and sample index page
mkdir -p pb_public
cat > pb_public/index.html <<'EOF'
<!DOCTYPE html><html lang="de"><head><meta charset="utf-8"></head><body><h1>Under construction...</h1></body></html>
EOF
# Download and install Filebrowser
cd /myapps/filebrowser
wget -q "https://github.com/filebrowser/filebrowser/releases/download/v${FILEBROWSER_VERSION}/linux-amd64-filebrowser.tar.gz"
tar -xzf linux-amd64-filebrowser.tar.gz
rm linux-amd64-filebrowser.tar.gz
chmod +x filebrowser
# Configure Supervisor for Pocketbase
cat > /etc/supervisor/conf.d/pocketbase.conf <<'EOF'
[program:pocketbase]
directory=/myapps/pocketbase
command=/myapps/pocketbase/pocketbase serve --http=127.0.0.1:8090
autostart=true
autorestart=true
stderr_logfile=/myapps/pocketbase/pocketbase.err.log
stdout_logfile=/myapps/pocketbase/pocketbase.out.log
logfile_maxbytes=10MB
logfile_backups=5
user=root
EOF
# Configure Supervisor for Filebrowser
cat > /etc/supervisor/conf.d/filebrowser.conf <<'EOF'
[program:filebrowser]
directory=/myapps/filebrowser
command=/myapps/filebrowser/filebrowser -r /myapps/pocketbase -a 127.0.0.1 -p 8091 --baseurl /filebrowser
autostart=false
autorestart=true
stderr_logfile=/myapps/filebrowser/filebrowser.err.log
stdout_logfile=/myapps/filebrowser/filebrowser.out.log
logfile_maxbytes=10MB
logfile_backups=5
user=root
EOF
# Start services with Supervisor
supervisorctl reread
supervisorctl update
sleep 2
# Configure Caddy
cat > /etc/caddy/Caddyfile <<EOF
${CUSTOM_DOMAIN} {
# Limit file upload size
request_body {
max_size 10MB
}
# Filebrowser (must come before root)
# Redirect /filebrowser to /filebrowser/ with trailing slash
handle /filebrowser {
redir {path}/ permanent
}
handle /filebrowser/* {
reverse_proxy localhost:8091
}
# Pocketbase at root (catches everything else)
handle {
reverse_proxy localhost:8090 {
transport http {
read_timeout 360s
}
}
}
}
EOF
# Reload Caddy
systemctl reload caddy
# Configure SSH security (key-based authentication only)
sed -i 's/^#*PubkeyAuthentication.*/PubkeyAuthentication yes/' /etc/ssh/sshd_config
sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
sed -i 's/^#*ChallengeResponseAuthentication.*/ChallengeResponseAuthentication no/' /etc/ssh/sshd_config
sed -i 's/^#*UsePAM.*/UsePAM yes/' /etc/ssh/sshd_config
systemctl restart ssh
# Configure network security settings (kernel parameters)
# Replace any line containing these parameters with the correct values
sed -i '/net\.ipv4\.conf\.default\.rp_filter/c\net.ipv4.conf.default.rp_filter=1' /etc/sysctl.conf
sed -i '/net\.ipv4\.conf\.all\.rp_filter/c\net.ipv4.conf.all.rp_filter=1' /etc/sysctl.conf
sed -i '/net\.ipv4\.conf\.all\.accept_redirects/c\net.ipv4.conf.all.accept_redirects=0' /etc/sysctl.conf
sed -i '/net\.ipv4\.conf\.default\.accept_redirects/c\net.ipv4.conf.default.accept_redirects=0' /etc/sysctl.conf
sed -i '/net\.ipv4\.conf\.all\.send_redirects/c\net.ipv4.conf.all.send_redirects=0' /etc/sysctl.conf
sed -i '/net\.ipv4\.conf\.all\.log_martians/c\net.ipv4.conf.all.log_martians=1' /etc/sysctl.conf
# Apply network security settings
sysctl -p
# Create completion marker
echo "Installation completed at $(date)" > /var/log/setup-complete.logImportant: After using the launch script:
- Wait 3-5 minutes for installation to complete
- Add HTTPS firewall rule in Lightsail Console (Networking tab → Add rule for HTTPS TCP 443)
- Check installation:
cat /var/log/setup-complete.log - Test applications:
- Pocketbase:
http://YOUR_IP/_/(login with your configured email/password) - Filebrowser:
sudo supervisorctl start filebrowser, thenhttp://YOUR_IP/filebrowser
- Pocketbase:
If you set a custom domain in the script:
5. Point your domain to the instance IP in Route 53 (Create an A Record)
6. Wait for DNS propagation (1-5 minutes, verify with nslookup your-domain.com)
7. SSH in and run: sudo systemctl reload caddy
8. Access via HTTPS at your domain
Note: If you keep CUSTOM_DOMAIN=":80", enable HTTPS later by editing /etc/caddy/Caddyfile and reloading Caddy.
That's it! You now have both applications running with automatic HTTPS support and enhanced security hardening thanks to Caddy, SSHGuard, and kernel network security settings. 🚀