Setup reverse proxy Sphinx docs
Setup reverse proxy Sphinx docs
This example creates a Sphinx 8 documentation site, serves it with sphinx-autobuild on port 4000, and proxies a Devilbox virtual host to that local documentation server.
Overview
| Project name | Container path | Database | TLD_SUFFIX | Project URL |
|---|---|---|---|---|
my-sphinx | /shared/httpd/my-sphinx | none | lvh.me | http://my-sphinx.lvh.me / https://my-sphinx.lvh.me |
The Sphinx server listens on port 4000 inside the PHP container. Devilbox proxies the virtual host to php:4000.
Prerequisites
- Devilbox with PHP, HTTPD, and Bind services.
- Python 3.12 and
pipavailable in the selected PHP image, or a startup script that installs them into that image. - Docker Compose v2 through Docker.
Start the stack:
./dvl.sh up php httpd bindWalk through
It will be ready in nine steps:
- Enter the PHP container.
- Create a new virtual host directory.
- Create a basic Sphinx project.
- Create a placeholder
htdocsdirectory. - Add reverse-proxy vhost-gen config files.
- Create an autostart script.
- Verify DNS.
- Restart Devilbox.
- Open the documentation in a browser.
1. Enter the PHP container
./dvl.sh shell php83Confirm Python:
python3 --versionpip --versionUse Python 3.12 where available.
2. Create the vhost directory
mkdir -p /shared/httpd/my-sphinxcd /shared/httpd/my-sphinx3. Create a basic Sphinx project
mkdir doccd docCreate conf.py:
project = 'My Docs'extensions = []source_suffix = '.rst'master_doc = 'index'html_theme = 'alabaster'exclude_patterns = ['_build/*']Create index.rst:
*******My Docs*******
Description
.. toctree:: :maxdepth: 2
page1Create page1.rst:
******Page 1******
Hello world4. Create a placeholder docroot
Reverse-proxy projects still need an htdocs directory for the Devilbox intranet virtual host checks:
cd /shared/httpd/my-sphinxmkdir htdocs5. Add reverse-proxy vhost-gen config files
Leave the shell and copy templates on the host:
exitcd /path/to/devilboxmkdir -p data/www/my-sphinx/.devilboxcp cfg/vhost-gen/apache22.yml-example-rproxy data/www/my-sphinx/.devilbox/apache22.ymlcp cfg/vhost-gen/apache24.yml-example-rproxy data/www/my-sphinx/.devilbox/apache24.ymlcp cfg/vhost-gen/nginx.yml-example-rproxy data/www/my-sphinx/.devilbox/nginx.ymlEdit each copied template and change the upstream port from 8000 to 4000.
Apache templates should contain:
ProxyPass / http://php:4000/ProxyPassReverse / http://php:4000/The Nginx template should contain:
location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://php:4000;}6. Create an autostart script
Create a startup script for the PHP 8.3 container. If you use another PHP container, place it in that matching startup directory.
cd /path/to/devilboxmkdir -p cfg/php-startup-8.3vi cfg/php-startup-8.3/my-sphinx.sh#!/usr/bin/env bashset -e
python3 -m pip install --user 'sphinx>=8,<9' 'sphinx-autobuild>=2024.10'su - devilbox -c 'cd /shared/httpd/my-sphinx/doc && python3 -m sphinx_autobuild . _build/html -p 4000 -H 0.0.0.0' &Make it executable:
chmod +x cfg/php-startup-8.3/my-sphinx.sh7. Verify DNS
my-sphinx.lvh.me resolves to localhost by default. Add a hosts entry only when using a custom suffix.
8. Restart Devilbox
./dvl.sh restartOr recycle the needed services:
./dvl.sh down./dvl.sh up php httpd bind9. Open your browser
Visit http://my-sphinx.lvh.me or https://my-sphinx.lvh.me. The web server proxies requests to sphinx-autobuild on port 4000.
Next steps
- Pin Sphinx extensions in a project-level requirements file.
- Move Python dependencies to a dedicated container if they conflict with PHP image tooling.
- Configure trusted HTTPS before sharing local documentation previews.