This repository has been archived on 2026-05-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
shelter-plugins/docs/NGINX-STATIC-HOSTING.md
2026-05-18 22:02:04 +03:00

213 lines
4.5 KiB
Markdown

# Hosting Shelter Plugins with NGINX
This guide walks you through hosting the built plugin files using NGINX on your own server.
## Prerequisites
- A server running NGINX
- Access to the server via SSH
- Basic familiarity with Linux command line
## Step 1: Prepare the Plugin Files
First, build the plugins locally using Lune:
```bash
# Install pnpm if you haven't already
npm install -g pnpm
# Install dependencies
pnpm install
# Build the plugins
pnpm lune ci
```
This creates the built plugin files in the `dist/` directory. Each plugin gets a folder matching its name (e.g., `dist/gpt-unslothed/`), containing:
- `plugin.js` — the bundled plugin code (all JSX/JS sources are bundled into a single file)
- `plugin.json` — the plugin manifest
Optionally, build the static website (SSG) for plugin documentation pages:
```bash
# Build the static website (includes plugin pages and index)
pnpm lune ssg ci
```
## Step 2: Set Up the Web Directory
Create a directory for the static files:
```bash
# Create the directory (you can change the path as needed)
sudo mkdir -p /var/www/shelter-plugins
# Copy the built files
sudo cp -r dist/* /var/www/shelter-plugins/
```
## Step 3: Configure NGINX
Create a new NGINX configuration file:
```bash
sudo nano /etc/nginx/sites-available/shelter-plugins
```
Add the following configuration:
```nginx
server {
listen 80;
server_name plugins.your-domain.com; # Change to your domain
root /var/www/shelter-plugins;
index index.html;
# Serve plugin files (JS and JSON)
location /gpt-unslothed {
try_files $uri $uri/ =404;
}
# Serve preview images
location /previews {
default_type image/png;
try_files $uri $uri/ =404;
}
# Catch-all for 404
location = /404.html {
internal;
}
# Redirect all other requests to 404
location / {
return 404;
}
}
```
### Configuration Notes
- Change `plugins.your-domain.com` to your actual domain or IP address
- The `try_files` directive lets NGINX auto-detect the correct MIME type for each file
- The configuration serves plugins from paths like `http://plugins.your-domain.com/gpt-unslothed/`
## Step 4: Enable the Site
```bash
# Enable the site
sudo ln -s /etc/nginx/sites-available/shelter-plugins /etc/nginx/sites-enabled/
# Test the configuration
sudo nginx -t
# Reload NGINX
sudo systemctl reload nginx
```
## Step 5: Use in Shelter
In Shelter, add the plugin using the URL:
```
http://plugins.your-domain.com/gpt-unslothed/plugin.json
```
Or if using HTTPS (recommended):
```
https://plugins.your-domain.com/gpt-unslothed/plugin.json
```
## Optional: Set Up HTTPS with Let's Encrypt
Install Certbot and get an SSL certificate:
```bash
# Install Certbot (Ubuntu/Debian)
sudo apt update
sudo apt install certbot python3-certbot-nginx
# Get the certificate
sudo certbot --nginx -d plugins.your-domain.com
```
Certbot will automatically update your NGINX configuration to use HTTPS.
## Automation: Deploying Updates
To make updates easier, you can create a simple deployment script:
```bash
#!/bin/bash
# deploy.sh
set -e
# Build plugins
echo "Building plugins..."
pnpm lune ci
# Build static website (optional, for documentation pages)
echo "Building static website..."
pnpm lune ssg ci
# Copy files
echo "Copying files to web directory..."
sudo rsync -av --delete dist/ /var/www/shelter-plugins/
# Reload NGINX (optional)
# sudo systemctl reload nginx
echo "Deployment complete!"
```
Make it executable and run it when you want to deploy:
```bash
chmod +x deploy.sh
./deploy.sh
```
## File Structure
After deployment, your server should look like this:
```
/var/www/shelter-plugins/
└── gpt-unslothed/
├── plugin.json
└── plugin.js
```
## Troubleshooting
### 404 Not Found
- Ensure the `dist/` directory contents were copied correctly
- Check that your NGINX site is enabled: `ls /etc/nginx/sites-enabled/`
- Check NGINX error logs: `sudo tail -f /var/log/nginx/error.log`
### Plugin not loading in Shelter
- Make sure the URL points to `plugin.json`, not the directory
- Check browser console for CORS errors (may need to add CORS headers)
### Adding CORS headers
If Shelter is experiencing CORS issues, add these headers to your NGINX config:
```nginx
location / {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Content-Type';
if ($request_method = 'OPTIONS') {
return 204;
}
}
```