Complete support for subdirectory hosting

Fixes #186
This commit is contained in:
Christopher C. Wells 2022-02-26 15:55:16 -08:00
parent 20d9cab158
commit c19d6cc6b9
6 changed files with 84 additions and 9 deletions

View File

@ -206,7 +206,7 @@ STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.AppDirectoriesFinder", "django.contrib.staticfiles.finders.AppDirectoriesFinder",
] ]
STATIC_URL = "static/" STATIC_URL = os.path.join(os.environ.get("SUB_PATH") or "", "static/")
STATIC_ROOT = os.path.join(BASE_DIR, "static") STATIC_ROOT = os.path.join(BASE_DIR, "static")

View File

@ -162,6 +162,17 @@ came in via HTTPS).
- [`ALLOWED_HOSTS`](#allowed_hosts) - [`ALLOWED_HOSTS`](#allowed_hosts)
- [`CSRF_TRUSTED_ORIGINS`](#csrf_trusted_origins) - [`CSRF_TRUSTED_ORIGINS`](#csrf_trusted_origins)
## `SUB_PATH`
*Default:* `None`
If Baby Buddy is hosted in a subdirectory of another server (e.g., `http://www.example.com/babybuddy`)
this must be set to the subdirectory path (e.g., `/babybuddy`) for correct handling of
application configuration.
Additional steps are required! See [Subdirectory configuration](subdirectory.md) for
details.
## `TIME_ZONE` ## `TIME_ZONE`
*Default:* `UTC` *Default:* `UTC`

View File

@ -76,9 +76,9 @@ requirements are Python, a web server, an application server, and a database.
### Example deployment ### Example deployment
*This example assumes a 512 MB VPS instance with Ubuntu 18.04.* It uses Python 3.6+, *This example assumes a 1 GB VPS instance with Ubuntu 20.04.* It uses Python 3.8,
nginx, uwsgi and sqlite. It should be sufficient for a few users (e.g., two parents nginx, uwsgi and sqlite. It should be sufficient for a few users (e.g., two parents
and 1+ child). and any number of children).
1. Install system packages 1. Install system packages
@ -103,12 +103,9 @@ and 1+ child).
cd /var/www/babybuddy/public cd /var/www/babybuddy/public
1. Set pipenv to install locally. 1. Initiate and enter a Python environment with Pipenv locally.
export PIPENV_VENV_IN_PROJECT=1 export PIPENV_VENV_IN_PROJECT=1
1. Initiate and enter the Python environment
pipenv install --three pipenv install --three
pipenv shell pipenv shell

View File

@ -1,4 +1,4 @@
# Proxy Configurations # Proxy configuration
Configuring Baby Buddy to run behind a proxy may require some additional configuration Configuring Baby Buddy to run behind a proxy may require some additional configuration
depending on the individual proxy configuration. Baby Buddy's environment variables for depending on the individual proxy configuration. Baby Buddy's environment variables for

View File

@ -0,0 +1,61 @@
# Subdirectory configuration
Baby Buddy's default configuration assumes deployment in to the root of a web server.
Some additional configuration is required to install Baby Buddy in a subdirectory of a
server instead (e.g., to `http://www.example.com/babybuddy`).
## Minimum version
Baby Buddy added full support for subdirectory installing in version **1.10.2**. While
it is still possible to do a subdirectory installation in older versions of Baby Buddy
it is not recommended.
## [`SUB_PATH`](../configuration#sub_path)
Set this environment variable to the subdirectory of the Baby Buddy installation. E.g.,
`SUB_PATH=/babybuddy` if the desired URL is `http://www.example.com/babybuddy`).
## uWSGI + NGINX configuration
When using uWSGI and NGINX (as in the [example deployment](deployment.md#example-deployment))
the following configurations are required.
*Assume the subdirectory `babybuddy` for configuration change examples below but this
can be anything includes multiple subdirectories (e.g., `/my/apps/babybuddy`). Other
paths used in these examples also assume a configuration based on the
[example deployment](deployment.md#example-deployment).*
### uWSGI
In the app configuration replace the `module` declaration with a `mount` declaration and
add the `manage-script-name` declaration and [`SUB_PATH`](../configuration#sub_path)
environment variable to the `[uwsgi]` configuration block.
``` diff
- module = %(project).wsgi:application
+ mount = /babybuddy=%(project).wsgi:application
+ manage-script-name = true
+ env = SUB_PATH=/babybuddy
```
### NGINX
Alter the NGINX `server` configuration to include the desired subdirectory path in the
app (Baby Buddy root) and media `location` declarations *and* add a new declaration for
the static `location`.
``` diff
- location / {
+ location /babybuddy {
```
``` diff
+ location /babybuddy/static {
+ alias /var/www/babybuddy/public/static;
+ }
```
``` diff
- location /media {
+ location /babybuddy/media {
```

View File

@ -1,10 +1,16 @@
extra_css: extra_css:
- css/extras.css - css/extras.css
markdown_extensions:
- pymdownx.highlight
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.superfences
nav: nav:
- 'index.md' - 'index.md'
- 'Setup': - 'Setup':
- 'setup/deployment.md' - 'setup/deployment.md'
- 'setup/configuration.md' - 'setup/configuration.md'
- 'setup/subdirectory.md'
- 'setup/proxy.md' - 'setup/proxy.md'
- 'User Guide': - 'User Guide':
- 'user-guide/getting-started.md' - 'user-guide/getting-started.md'