Use nginx to serve media files if cloud provider is None

This commit is contained in:
Bruno Alla 2023-01-31 23:31:44 +00:00
parent 18b510d09a
commit ebbdb16557
No known key found for this signature in database
6 changed files with 8 additions and 12 deletions

View File

@ -29,7 +29,7 @@ production-ready Django projects quickly.
- Optional basic ASGI setup for Websockets
- Optional custom static build using Gulp or Webpack
- Send emails via [Anymail](https://github.com/anymail/django-anymail) (using [Mailgun](http://www.mailgun.com/) by default or Amazon SES if AWS is selected cloud provider, but switchable)
- Media storage using Amazon S3, Google Cloud Storage or Azure Storage
- Media storage using Amazon S3, Google Cloud Storage, Azure Storage or nginx
- Docker support using [docker-compose](https://github.com/docker/compose) for development and production (using [Traefik](https://traefik.io/) with [LetsEncrypt](https://letsencrypt.org/) support)
- [Procfile](https://devcenter.heroku.com/articles/procfile) for deploying to Heroku
- Instructions for deploying to [PythonAnywhere](https://www.pythonanywhere.com/)

View File

@ -28,7 +28,6 @@
"AWS",
"GCP",
"Azure",
"nginx",
"None"
],
"mail_service": [

View File

@ -492,10 +492,6 @@ def main():
)
if "{{ cookiecutter.cloud_provider }}" == "None":
print(
WARNING + "You chose not to use a cloud provider, "
"media files won't be served in production." + TERMINATOR
)
remove_storages_module()
if "{{ cookiecutter.use_celery }}".lower() == "n":

View File

@ -57,7 +57,7 @@ http:
# https://docs.traefik.io/master/routing/routers/#certresolver
certResolver: letsencrypt
{%- endif %}
{%- if cookiecutter.cloud_provider == 'nginx' %}
{%- if cookiecutter.cloud_provider == 'None' %}
web-media-router:
rule: "Host(`{{ cookiecutter.domain_name }}`) && PathPrefix(`/media/`)"
@ -89,7 +89,8 @@ http:
servers:
- url: http://flower:5555
{%- endif %}
{%- if cookiecutter.cloud_provider == 'nginx' %}
{%- if cookiecutter.cloud_provider == 'None' %}
django-media:
loadBalancer:
servers:

View File

@ -64,7 +64,7 @@ SECURE_CONTENT_TYPE_NOSNIFF = env.bool(
"DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True
)
{% if cookiecutter.cloud_provider != 'None' and cookiecutter.cloud_provider != 'nginx' -%}
{% if cookiecutter.cloud_provider != 'None' -%}
# STORAGES
# ------------------------------------------------------------------------------
# https://django-storages.readthedocs.io/en/latest/#installation

View File

@ -4,7 +4,7 @@ volumes:
production_postgres_data: {}
production_postgres_data_backups: {}
production_traefik: {}
{%- if cookiecutter.cloud_provider == 'nginx' %}
{%- if cookiecutter.cloud_provider == 'None' %}
production_django_media: {}
{%- endif %}
@ -27,7 +27,7 @@ services:
{%- endif %}
image: {{ cookiecutter.project_slug }}_production_django
{%- if cookiecutter.cloud_provider == 'nginx' %}
{%- if cookiecutter.cloud_provider == 'None' %}
volumes:
- production_django_media:/app/{{ cookiecutter.project_slug }}/media
{%- endif %}
@ -96,7 +96,7 @@ services:
volumes:
- production_postgres_data_backups:/backups:z
{%- endif %}
{%- if cookiecutter.cloud_provider == 'nginx' %}
{%- if cookiecutter.cloud_provider == 'None' %}
nginx:
build:
context: .