diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md new file mode 100644 index 0000000..db76a76 --- /dev/null +++ b/DEPLOYMENT.md @@ -0,0 +1,106 @@ +# Deployment Guide for Hetzner VPS + +This guide will help you deploy your SvelteKit application on your Hetzner VPS. + +## Prerequisites + +- Node.js installed on your VPS +- PM2 installed globally (`npm install -g pm2`) +- Nginx installed and running + +## Deployment Steps + +### 1. Build the Application + +On your VPS, navigate to your project directory: + +```bash +cd /floter-design +npm install +npm run build +``` + +### 2. Create Logs Directory (for PM2) + +```bash +mkdir -p /floter-design/logs +``` + +### 3. Start the Application with PM2 + +```bash +cd /floter-design +pm2 start ecosystem.config.cjs +pm2 save +pm2 startup +``` + +The last command (`pm2 startup`) will give you a command to run with sudo to enable PM2 to start on system boot. + +### 4. Configure Nginx + +1. Copy the nginx configuration: + ```bash + sudo cp nginx.conf.example /etc/nginx/sites-available/floter-design + ``` + +2. Edit the configuration with your domain: + ```bash + sudo nano /etc/nginx/sites-available/floter-design + ``` + Replace `your-domain.com` with your actual domain name. + +3. Enable the site: + ```bash + sudo ln -s /etc/nginx/sites-available/floter-design /etc/nginx/sites-enabled/ + ``` + +4. Test nginx configuration: + ```bash + sudo nginx -t + ``` + +5. Reload nginx: + ```bash + sudo systemctl reload nginx + ``` + +### 5. Set Up SSL (Optional but Recommended) + +If you want HTTPS, use Let's Encrypt: + +```bash +sudo apt install certbot python3-certbot-nginx +sudo certbot --nginx -d your-domain.com -d www.your-domain.com +``` + +Then uncomment the HTTPS server block in your nginx config and reload. + +## Useful Commands + +### PM2 Commands + +- View running apps: `pm2 list` +- View logs: `pm2 logs floter-design` +- Restart app: `pm2 restart floter-design` +- Stop app: `pm2 stop floter-design` +- Monitor: `pm2 monit` + +### Nginx Commands + +- Test config: `sudo nginx -t` +- Reload: `sudo systemctl reload nginx` +- Restart: `sudo systemctl restart nginx` +- Status: `sudo systemctl status nginx` + +## Troubleshooting + +- **Port already in use**: Change the PORT in `ecosystem.config.cjs` (default is 3001) or stop the process using that port +- **Port 3001 conflicts**: You can use any available port (3002, 3003, etc.) - just update both `ecosystem.config.cjs` and your nginx config +- **502 Bad Gateway**: Check if the Node.js server is running (`pm2 list`) and check logs (`pm2 logs`) +- **Permission errors**: Make sure the user running PM2 has proper permissions to the `/floter-design` directory + +## Environment Variables + +If you need to set environment variables, edit the `env` section in `ecosystem.config.cjs` or create a `.env` file in `/floter-design`. + diff --git a/ecosystem.config.cjs b/ecosystem.config.cjs new file mode 100644 index 0000000..09d83f8 --- /dev/null +++ b/ecosystem.config.cjs @@ -0,0 +1,22 @@ +module.exports = { + apps: [{ + name: 'floter-design', + script: './build/index.js', + cwd: '/floter-design', + instances: 1, + exec_mode: 'fork', + env: { + NODE_ENV: 'production', + PORT: 3001, + HOST: '0.0.0.0' + }, + error_file: './logs/err.log', + out_file: './logs/out.log', + log_date_format: 'YYYY-MM-DD HH:mm:ss Z', + merge_logs: true, + autorestart: true, + watch: false, + max_memory_restart: '1G' + }] +}; + diff --git a/nginx.conf.example b/nginx.conf.example new file mode 100644 index 0000000..d7cba3c --- /dev/null +++ b/nginx.conf.example @@ -0,0 +1,65 @@ +# Example nginx configuration for SvelteKit Node.js app +# Place this in: /etc/nginx/sites-available/floter-design +# Then create symlink: sudo ln -s /etc/nginx/sites-available/floter-design /etc/nginx/sites-enabled/ +# Test config: sudo nginx -t +# Reload: sudo systemctl reload nginx + +server { + listen 80; + listen [::]:80; + server_name your-domain.com www.your-domain.com; # Replace with your domain + + # Redirect HTTP to HTTPS (uncomment after setting up SSL) + # return 301 https://$server_name$request_uri; + + # For now, proxy directly to Node.js (remove this block after SSL setup) + location / { + proxy_pass http://localhost:3001; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_cache_bypass $http_upgrade; + + # Increase timeouts for long-running requests + proxy_connect_timeout 60s; + proxy_send_timeout 60s; + proxy_read_timeout 60s; + } +} + +# HTTPS configuration (uncomment and configure after SSL certificate setup) +# server { +# listen 443 ssl http2; +# listen [::]:443 ssl http2; +# server_name your-domain.com www.your-domain.com; +# +# # SSL certificate paths (use Let's Encrypt or your certificate) +# ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem; +# ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem; +# +# # SSL configuration +# ssl_protocols TLSv1.2 TLSv1.3; +# ssl_ciphers HIGH:!aNULL:!MD5; +# ssl_prefer_server_ciphers on; +# +# location / { +# proxy_pass http://localhost:3001; +# proxy_http_version 1.1; +# proxy_set_header Upgrade $http_upgrade; +# proxy_set_header Connection 'upgrade'; +# proxy_set_header Host $host; +# proxy_set_header X-Real-IP $remote_addr; +# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +# proxy_set_header X-Forwarded-Proto $scheme; +# proxy_cache_bypass $http_upgrade; +# +# proxy_connect_timeout 60s; +# proxy_send_timeout 60s; +# proxy_read_timeout 60s; +# } +# } +