# Deploying the Westminster Standards Site

Static HTML/CSS/JS site. Copy the folder to your server and configure Nginx. All paths are relative; for **subdirectory** deploy under WordPress, rebuild with a base prefix (see below).

## Quick start

```bash
sudo cp -r westminster-standards /var/www/standards
sudo chown -R www-data:www-data /var/www/standards
sudo cp /var/www/standards/nginx-wordpress.conf /etc/nginx/snippets/  # optional
```

## WordPress on the same server (most common issue)

WordPress uses a catch-all `location / { try_files ... /index.php; }` that **steals** `/standards/` unless you add a dedicated block **above** it.

### 1. Nginx config

Add to your WordPress `server { }` block **before** `location /`:

```nginx
# Trailing slash required for relative asset paths
location = /standards {
    return 301 /standards/;
}

# ^~ prevents WordPress PHP/static rules from intercepting
# Use root (NOT alias) — alias + try_files often causes HTTP 500
location ^~ /standards/ {
    root /var/www;
    index index.html;
}
```

Or include the ready-made snippet:

```nginx
include /var/www/standards/nginx-wordpress.conf;
```

**Copy path matters:** files must be at `/var/www/standards/index.html`, not `/var/www/standards/westminster-standards/index.html`.

```bash
# Correct — contents of the folder go directly in standards/
sudo cp -r westminster-standards/* /var/www/standards/
# OR
sudo rsync -a westminster-standards/ /var/www/standards/

# Wrong — nested folder (Nginx will 404/500)
sudo cp -r westminster-standards /var/www/standards   # creates .../standards/westminster-standards/
```

### 2. Rebuild with base prefix (fixes CSS/JS not loading)

Relative `css/main.css` and `js/data.js` resolve against the browser URL. Under `/standards/` you need either a trailing slash **or** a `<base>` tag. Rebuild on the server (or before copy):

```bash
cd /var/www/standards
WESTMINSTER_BASE=/standards/ python3 scripts/build_site.py
```

Then reload Nginx:

```bash
sudo nginx -t && sudo systemctl reload nginx
```

### 3. WordPress page slug conflict

If WordPress has a Page with slug `standards`, it can conflict. Rename or trash that WordPress page — the static site owns `/standards/`.

### 4. Verify

```bash
curl -sI https://yourdomain.com/standards/ | head -3
curl -sI https://yourdomain.com/standards/css/main.css | head -3
curl -sI https://yourdomain.com/standards/js/data.js | head -3
```

All three should return `200`. If CSS/JS return `404` or WordPress HTML, the location block order or `^~` prefix is wrong.

### 5. HTTP 500 troubleshooting

A **500** almost always means an Nginx config error, not the static files themselves.

```bash
# Read the actual error (run on your server)
sudo tail -30 /var/log/nginx/error.log

# Validate config before reload
sudo nginx -t
```

| Error log message | Fix |
|-------------------|-----|
| `rewrite or internal redirection cycle` | Remove `try_files` from the `/standards/` block; use the `root` config above |
| `alias` / `failed (20: Not a directory)` | Switch from `alias` to `root /var/www` as above |
| `Permission denied` | `sudo chown -R www-data:www-data /var/www/standards && sudo chmod -R a+rX /var/www/standards` |
| No error, still 500 | Confirm files exist: `ls -la /var/www/standards/index.html` |

Test locally on the server (bypasses WordPress DNS):

```bash
curl -sI -H 'Host: yourdomain.com' http://127.0.0.1/standards/ --resolve yourdomain.com:80:127.0.0.1
```

## Option B: Subdomain (no WordPress conflict)

```nginx
server {
    listen 443 ssl http2;
    server_name standards.yourdomain.com;

    root /var/www/standards;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}
```

Build **without** `WESTMINSTER_BASE` for subdomain deploy.

## Build options

| Deploy path | Build command |
|-------------|---------------|
| `/standards/` on WordPress host | `WESTMINSTER_BASE=/standards/ python3 scripts/build_site.py` |
| Subdomain or dedicated vhost | `python3 scripts/build_site.py` |

## File layout

```
westminster-standards/
├── index.html
├── about.html
├── confession.html
├── larger-catechism.html
├── shorter-catechism.html
├── directory.html
├── css/main.css
├── js/data.js, standards.js, ui/search.js, ui/sidebar.js, app.js
├── nginx-wordpress.conf
└── scripts/build_site.py
```

No runtime dependencies on the server beyond Nginx (and Python only to rebuild HTML).