feat: Update server deployment guide with improved Caddy config and troubleshooting
Some checks failed
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Has been cancelled
Some checks failed
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Has been cancelled
This commit is contained in:
@@ -83,6 +83,11 @@ Add the following content:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Load nvm (Node Version Manager)
|
||||||
|
export NVM_DIR="$HOME/.nvm"
|
||||||
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||||
|
|
||||||
cd /root/code/git.ourworld.tf/tfgrid/tfgrid-economics
|
cd /root/code/git.ourworld.tf/tfgrid/tfgrid-economics
|
||||||
|
|
||||||
# Pull latest changes
|
# Pull latest changes
|
||||||
@@ -98,6 +103,11 @@ npm run build
|
|||||||
exec npx serve -s build -l 9997
|
exec npx serve -s build -l 9997
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Note**: This script loads nvm before running npm commands. If you're not using nvm, replace the nvm lines with:
|
||||||
|
```bash
|
||||||
|
export PATH="/usr/local/bin:/usr/bin:/bin:$PATH"
|
||||||
|
```
|
||||||
|
|
||||||
Make the script executable:
|
Make the script executable:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -118,48 +128,54 @@ exec: "/bin/bash -c /etc/zinit/cmds/tfgrid-economics.sh"
|
|||||||
|
|
||||||
## Step 4: Configure Caddy
|
## Step 4: Configure Caddy
|
||||||
|
|
||||||
Navigate to your Caddy configuration directory:
|
Navigate to your Caddy configuration directory (location may vary based on your setup).
|
||||||
|
|
||||||
### 4.1 Add Import to Main Caddyfile
|
### 4.1 Find the Existing threefold.info Configuration
|
||||||
|
|
||||||
Edit the main Caddyfile and add the import statement:
|
First, locate which file contains the `threefold.info` domain block:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
nano Caddyfile
|
grep -l "threefold.info" *.caddy
|
||||||
```
|
```
|
||||||
|
|
||||||
Add this line:
|
In this setup, it's in `info.caddy`.
|
||||||
```
|
|
||||||
import economics.caddy
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4.2 Create Economics Caddy Config
|
### 4.2 Add Economics Route to Existing Configuration
|
||||||
|
|
||||||
Create the dedicated configuration file:
|
Edit the file containing the `threefold.info` block:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
nano economics.caddy
|
# Backup first
|
||||||
|
cp info.caddy info.caddy.backup
|
||||||
|
|
||||||
|
# Edit the file
|
||||||
|
nano info.caddy
|
||||||
```
|
```
|
||||||
|
|
||||||
Add the following content:
|
Add the `handle_path` block **at the beginning** of the `threefold.info` block (before `root` and `file_server`):
|
||||||
|
|
||||||
```
|
```
|
||||||
# TFGrid Economics
|
info.ourworld.tf threefold.info info.i.threefold.me {
|
||||||
threefold.info {
|
# TFGrid Economics - MUST come before file_server
|
||||||
handle_path /economics* {
|
handle_path /economics* {
|
||||||
reverse_proxy localhost:9997 {
|
reverse_proxy localhost:9997 {
|
||||||
header_up Host {host}
|
header_up Host {host}
|
||||||
header_up X-Real-IP {remote}
|
header_up X-Real-IP {remote}
|
||||||
header_up X-Forwarded-Proto {scheme}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Default file server for other content
|
||||||
|
root * /root/hero/www/info
|
||||||
|
encode gzip
|
||||||
|
file_server
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Notes:**
|
**Important Notes:**
|
||||||
|
- The `handle_path` must come **before** `file_server` to take priority
|
||||||
- The `handle_path` directive strips `/economics` from the path before forwarding to port 9997
|
- The `handle_path` directive strips `/economics` from the path before forwarding to port 9997
|
||||||
- If you already have other services using `threefold.info`, add the `handle_path` block to the existing configuration
|
- Don't create a separate file with another `threefold.info` block - Caddy will try to provision SSL certs for invalid hostnames
|
||||||
- Multiple `handle_path` blocks can coexist in the same domain config
|
- This approach works when `threefold.info` is already defined in an existing file
|
||||||
|
|
||||||
## Step 5: Start Services with zinit
|
## Step 5: Start Services with zinit
|
||||||
|
|
||||||
@@ -236,6 +252,34 @@ Check for errors in the application logs:
|
|||||||
zinit log tfgrid-economics
|
zinit log tfgrid-economics
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### npm/npx Command Not Found
|
||||||
|
|
||||||
|
If zinit can't find npm, you need to add Node.js to the PATH in the script.
|
||||||
|
|
||||||
|
First, find where Node.js is installed:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
which node
|
||||||
|
which npm
|
||||||
|
which npx
|
||||||
|
```
|
||||||
|
|
||||||
|
Common locations:
|
||||||
|
- `/usr/local/bin/` (standard install)
|
||||||
|
- `/usr/bin/` (system package manager)
|
||||||
|
- `~/.nvm/` (nvm installation)
|
||||||
|
|
||||||
|
Then update `/etc/zinit/cmds/tfgrid-economics.sh` with the correct PATH:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# For standard installation
|
||||||
|
export PATH="/usr/local/bin:/usr/bin:/bin:$PATH"
|
||||||
|
|
||||||
|
# For nvm installation
|
||||||
|
export NVM_DIR="$HOME/.nvm"
|
||||||
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||||
|
```
|
||||||
|
|
||||||
### Build Failures
|
### Build Failures
|
||||||
|
|
||||||
Check if Node.js and dependencies are properly installed:
|
Check if Node.js and dependencies are properly installed:
|
||||||
@@ -273,7 +317,7 @@ Verify Caddy configuration:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Test Caddy configuration
|
# Test Caddy configuration
|
||||||
caddy validate --config /root/code/github/despiegk/env_web/ourworld/ovh1_web_current/caddy/Caddyfile
|
caddy validate --config Caddyfile
|
||||||
|
|
||||||
# Check Caddy logs
|
# Check Caddy logs
|
||||||
zinit log caddy
|
zinit log caddy
|
||||||
@@ -282,6 +326,23 @@ zinit log caddy
|
|||||||
zinit restart caddy
|
zinit restart caddy
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Caddy SSL Certificate Errors for "handle_path"
|
||||||
|
|
||||||
|
If you see errors like `Cannot issue for "handle_path": Domain name contains an invalid character`, you've likely created a separate `.caddy` file with a domain block that should be merged into an existing file instead.
|
||||||
|
|
||||||
|
**Problem:** Creating a standalone file like:
|
||||||
|
```
|
||||||
|
threefold.info {
|
||||||
|
handle_path /economics* {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
When `threefold.info` is already defined elsewhere, this causes Caddy to try provisioning certs incorrectly.
|
||||||
|
|
||||||
|
**Solution:** Add the `handle_path` block to the existing file that contains the `threefold.info` domain block.
|
||||||
|
|
||||||
### Git Authentication Issues
|
### Git Authentication Issues
|
||||||
|
|
||||||
If the repository requires authentication:
|
If the repository requires authentication:
|
||||||
@@ -300,17 +361,24 @@ git checkout main
|
|||||||
|
|
||||||
## Alternative: Direct Caddy File Server
|
## Alternative: Direct Caddy File Server
|
||||||
|
|
||||||
Instead of using `npx serve`, you can configure Caddy to serve the static files directly.
|
Instead of using `npx serve` with zinit, you can configure Caddy to serve the static files directly.
|
||||||
|
|
||||||
|
**Edit the file containing `threefold.info` (e.g., `info.caddy`):**
|
||||||
|
|
||||||
**Edit `economics.caddy`:**
|
|
||||||
```
|
```
|
||||||
threefold.info {
|
info.ourworld.tf threefold.info info.i.threefold.me {
|
||||||
|
# TFGrid Economics - Direct file serving
|
||||||
handle_path /economics* {
|
handle_path /economics* {
|
||||||
root * /root/code/git.ourworld.tf/tfgrid/tfgrid-economics/build
|
root * /root/code/git.ourworld.tf/tfgrid/tfgrid-economics/build
|
||||||
file_server
|
|
||||||
try_files {path} {path}/ /index.html
|
try_files {path} {path}/ /index.html
|
||||||
encode gzip
|
encode gzip
|
||||||
|
file_server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Default file server for other content
|
||||||
|
root * /root/hero/www/info
|
||||||
|
encode gzip
|
||||||
|
file_server
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user