Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions docs/usage/preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,59 @@ will automatically reload the page you're on.

Files matched by [`draft_docs`][draft_docs] are included during preview, and a draft notice is added to draft pages. Draft pages are omitted from the default navigation and can be opened by URL. Files matched by [`exclude_docs`][exclude_docs] are excluded from preview.

## Reverse proxies

To preview a site through a reverse proxy, allow the URL used by the browser:

``` sh
zensical serve --external-origin https://docs.example.com
```

Specify the scheme (`http` or `https`), hostname, and port if needed, without a
path. Repeat `--external-origin` to allow more than one URL. No external URLs are
allowed by default.

The proxy must forward the browser's `Host` and WebSocket `Origin` headers and
support WebSocket upgrades for live reload. It connects to Zensical over HTTP;
HTTPS terminates at the proxy. If the proxy can reach Zensical on loopback, keep
the default `localhost:8000` bind address. For a proxy in another container or
on another machine, bind to an address it can reach:

``` sh
zensical serve --dev-addr 0.0.0.0:8000 \
--external-origin https://docs.example.com
```

!!! warning "Keep the preview private"

`--external-origin` checks request hosts and browser WebSocket origins. It
does not authenticate users or restrict client IP addresses. Restrict
browser access at the proxy and keep the connection to Zensical private.
In Docker, put both containers on a private network and do not publish
Zensical's port.

### Path prefixes

If the browser opens the preview at `https://docs.example.com/preview/`, set
[`site_url`][site_url] in the configuration used for that preview:

=== "`zensical.toml`"

``` toml
[project]
site_url = "https://docs.example.com/preview/"
```

=== "`mkdocs.yml`"

``` yaml
site_url: https://docs.example.com/preview/
```

Pass `--external-origin https://docs.example.com` without `/preview/`. The
proxy must forward the `/preview/` path unchanged, because Zensical uses the
path in `site_url` for serving.

## Options

The `serve` command accepts the following options:
Expand All @@ -38,8 +91,10 @@ The `serve` command accepts the following options:
| `--config-file` | `-f` | Path to the config file to use. |
| `--open` | `-o` | Open preview in default browser |
| `--dev-addr <IP:PORT>` | `-a` | IP address and port (default: localhost:8000) |
| `--external-origin` | | Allow a proxy URL for preview (repeatable). |
| `--help` | | Show a help message and exit. |

[draft_docs]: ../setup/basics.md#draft_docs
[exclude_docs]: ../setup/basics.md#exclude_docs
[live preview]: http://localhost:8000
[site_url]: ../setup/basics.md#site_url