2.6 KiB
2.6 KiB
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:
cd /floter-design
npm install
npm run build
2. Create Logs Directory (for PM2)
mkdir -p /floter-design/logs
3. Start the Application with PM2
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
-
Copy the nginx configuration:
sudo cp nginx.conf.example /etc/nginx/sites-available/floter-design -
Edit the configuration with your domain:
sudo nano /etc/nginx/sites-available/floter-designReplace
your-domain.comwith your actual domain name. -
Enable the site:
sudo ln -s /etc/nginx/sites-available/floter-design /etc/nginx/sites-enabled/ -
Test nginx configuration:
sudo nginx -t -
Reload nginx:
sudo systemctl reload nginx
5. Set Up SSL (Optional but Recommended)
If you want HTTPS, use Let's Encrypt:
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.cjsand 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-designdirectory
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.