avatars: Serve /user_avatars/ through Django, which offloads to nginx.

Moving `/user_avatars/` to being served partially through Django
removes the need for the `no_serve_uploads` nginx reconfiguring when
switching between S3 and local backends.  This is important because a
subsequent commit will move S3 attachments to being served through
nginx, which would make `no_serve_uploads` entirely nonsensical of a
name.

Serve the files through Django, with an offload for the actual image
response to an internal nginx route.  In development, serve the files
directly in Django.

We do _not_ mark the contents as immutable for caching purposes, since
the path for avatar images is hashed only by their user-id and a salt,
and as such are reused when a user's avatar is updated.
This commit is contained in:
Alex Vandiver
2022-12-06 21:24:43 +00:00
committed by Alex Vandiver
parent f0f4aa66e0
commit ed6d62a9e7
9 changed files with 114 additions and 77 deletions

View File

@@ -661,15 +661,6 @@ SSL/TLS termination.
Set to the port number if you [prefer to listen on a port other than
443](#using-an-alternate-port).
#### `no_serve_uploads`
To enable the [the S3 uploads backend][s3-uploads], one needs to both
configure `settings.py` and set this to true to configure
`nginx`. Remove this field to return to the local uploads backend (any
non-empty value is currently equivalent to true).
[s3-uploads]: upload-backends.md#s3-backend-configuration
#### `queue_workers_multiprocess`
By default, Zulip automatically detects whether the system has enough

View File

@@ -45,26 +45,6 @@ backend. To enable this backend, you need to do the following:
For certain AWS regions, you may need to set the `S3_REGION`
setting to your default AWS region's code (e.g. `"eu-central-1"`).
1. You will need to configure `nginx` to direct requests for uploaded
files to the Zulip server (which will then serve a redirect to the
appropriate place in S3), rather than serving them directly.
With Zulip 1.9.0 and newer, you can do this automatically with the
following commands run as root:
```bash
crudini --set /etc/zulip/zulip.conf application_server no_serve_uploads true
/home/zulip/deployments/current/scripts/zulip-puppet-apply
```
(The first line will update your `/etc/zulip/zulip.conf`).
With older Zulip, you need to edit
`/etc/nginx/sites-available/zulip-enterprise` to comment out the
`nginx` configuration block for `/user_avatars` and the
`include /etc/nginx/zulip-include/uploads.route` line and then
reload the `nginx` service (`service nginx reload`).
1. Finally, restart the Zulip server so that your settings changes
take effect
(`/home/zulip/deployments/current/scripts/restart-server`).