Deploy with Nginx
Host BentoPDF on your own server using Nginx.
Prerequisites
- Ubuntu/Debian server
- Nginx installed
- SSL certificate (recommended: Let's Encrypt)
Step 1: Build the Project
bash
git clone https://github.com/alam00000/bentopdf.git
cd bentopdf
npm install
npm run buildStep 2: Copy Files
bash
sudo mkdir -p /var/www/bentopdf
sudo cp -r dist/* /var/www/bentopdf/
sudo chown -R www-data:www-data /var/www/bentopdfStep 3: Nginx Configuration
Create /etc/nginx/sites-available/bentopdf:
nginx
server {
listen 80;
server_name your-domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name your-domain.com;
# SSL Configuration
ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
root /var/www/bentopdf;
index index.html;
# Gzip compression
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/wasm;
gzip_min_length 1000;
# WASM MIME type
types {
application/wasm wasm;
}
# Cache static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|wasm)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# SPA routing - serve index.html for all routes
location / {
try_files $uri $uri/ /index.html;
}
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
}Step 4: Enable the Site
bash
sudo ln -s /etc/nginx/sites-available/bentopdf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginxStep 5: SSL with Let's Encrypt
bash
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.comSubdirectory Deployment
To host at /pdf/:
nginx
location /pdf/ {
alias /var/www/bentopdf/;
try_files $uri $uri/ /pdf/index.html;
}Build with:
bash
BASE_URL=/pdf/ npm run buildPerformance Tuning
Add to nginx.conf:
nginx
http {
# Enable sendfile
sendfile on;
tcp_nopush on;
tcp_nodelay on;
# Increase buffer sizes
client_max_body_size 100M;
# Worker connections
worker_connections 2048;
}Troubleshooting
WASM Not Loading
Ensure MIME type is set:
nginx
types {
application/wasm wasm;
}502 Bad Gateway
Check Nginx error logs:
bash
sudo tail -f /var/log/nginx/error.log