diff --git a/babybuddy/settings/base.py b/babybuddy/settings/base.py index 82ac060f..579f3e7f 100644 --- a/babybuddy/settings/base.py +++ b/babybuddy/settings/base.py @@ -206,7 +206,7 @@ STATICFILES_FINDERS = [ "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") diff --git a/docs/setup/configuration.md b/docs/setup/configuration.md index e8d57934..8417ad48 100644 --- a/docs/setup/configuration.md +++ b/docs/setup/configuration.md @@ -162,6 +162,17 @@ came in via HTTPS). - [`ALLOWED_HOSTS`](#allowed_hosts) - [`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` *Default:* `UTC` diff --git a/docs/setup/deployment.md b/docs/setup/deployment.md index f870d3fd..016dd00d 100644 --- a/docs/setup/deployment.md +++ b/docs/setup/deployment.md @@ -76,9 +76,9 @@ requirements are Python, a web server, an application server, and a database. ### Example deployment -*This example assumes a 512 MB VPS instance with Ubuntu 18.04.* It uses Python 3.6+, -nginx, uwsgi and sqlite. It should be sufficient for a few users(e.g., two parents -and 1+ child). +*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 +and any number of children). 1. Install system packages @@ -103,12 +103,9 @@ and 1+ child). 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 - -1. Initiate and enter the Python environment - pipenv install --three pipenv shell diff --git a/docs/setup/proxy.md b/docs/setup/proxy.md index d828f296..caa4da08 100644 --- a/docs/setup/proxy.md +++ b/docs/setup/proxy.md @@ -1,4 +1,4 @@ -# Proxy Configurations +# Proxy 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 diff --git a/docs/setup/subdirectory.md b/docs/setup/subdirectory.md new file mode 100644 index 00000000..9514375b --- /dev/null +++ b/docs/setup/subdirectory.md @@ -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 { +``` \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 0b511c94..17859a4f 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,10 +1,16 @@ extra_css: - css/extras.css +markdown_extensions: + - pymdownx.highlight + - pymdownx.inlinehilite + - pymdownx.snippets + - pymdownx.superfences nav: - 'index.md' - 'Setup': - 'setup/deployment.md' - 'setup/configuration.md' + - 'setup/subdirectory.md' - 'setup/proxy.md' - 'User Guide': - 'user-guide/getting-started.md'