mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-14 17:04:53 +03:00
Add option to serve media files locally using nginx
This commit is contained in:
parent
b1fb6ed2d0
commit
9663305f1f
|
@ -63,6 +63,7 @@ Listed in alphabetical order.
|
|||
Anuj Bansal `@ahhda`_
|
||||
Arcuri Davide `@dadokkio`_
|
||||
Areski Belaid `@areski`_
|
||||
Arkadiusz Michał Ryś `@arkadiuszmichalrys`_
|
||||
Ashley Camba
|
||||
Barclay Gauld `@yunti`_
|
||||
Bartek `@btknu`_
|
||||
|
@ -233,6 +234,7 @@ Listed in alphabetical order.
|
|||
.. _@apirobot: https://github.com/apirobot
|
||||
.. _@archinal: https://github.com/archinal
|
||||
.. _@areski: https://github.com/areski
|
||||
.. _@arkadiuszmichalrys: https://github.com/ArkadiuszMichalRys
|
||||
.. _@arruda: https://github.com/arruda
|
||||
.. _@bertdemiranda: https://github.com/bertdemiranda
|
||||
.. _@bittner: https://github.com/bittner
|
||||
|
|
|
@ -47,7 +47,7 @@ Features
|
|||
* Comes with custom user model ready to go
|
||||
* Optional custom static build using Gulp and livereload
|
||||
* Send emails via Anymail_ (using Mailgun_ by default, but switchable)
|
||||
* Media storage using Amazon S3 or Google Cloud Storage
|
||||
* Media storage using Amazon S3, Google Cloud Storage or a local nginx instance
|
||||
* Docker support using docker-compose_ for development and production (using Traefik_ with LetsEncrypt_ support)
|
||||
* Procfile_ for deploying to Heroku
|
||||
* Instructions for deploying to PythonAnywhere_
|
||||
|
@ -85,7 +85,7 @@ Optional Integrations
|
|||
.. _PythonAnywhere: https://www.pythonanywhere.com/
|
||||
.. _Traefik: https://traefik.io/
|
||||
.. _LetsEncrypt: https://letsencrypt.org/
|
||||
.. _pre-commit: https://github.com/pre-commit/pre-commit
|
||||
.. _pre-commit: https://github.com/pre-commit/pre-commit
|
||||
|
||||
Constraints
|
||||
-----------
|
||||
|
@ -184,7 +184,8 @@ Answer the prompts with your own desired options_. For example::
|
|||
Select cloud_provider:
|
||||
1 - AWS
|
||||
2 - GCP
|
||||
3 - None
|
||||
3 - nginx
|
||||
4 - None
|
||||
Choose from 1, 2, 3 [1]: 1
|
||||
custom_bootstrap_compilation [n]: n
|
||||
Select open_source_license:
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
"cloud_provider": [
|
||||
"AWS",
|
||||
"GCP",
|
||||
"nginx",
|
||||
"None"
|
||||
],
|
||||
"use_drf": "n",
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
FROM nginx:1.17.8-alpine
|
||||
COPY ./compose/production/nginx/default.conf /etc/nginx/conf.d/default.conf
|
|
@ -0,0 +1,8 @@
|
|||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
location /media {
|
||||
autoindex on;
|
||||
alias /usr/share/nginx/media/;
|
||||
}
|
||||
}
|
|
@ -41,6 +41,16 @@ http:
|
|||
tls:
|
||||
# https://docs.traefik.io/master/routing/routers/#certresolver
|
||||
certResolver: letsencrypt
|
||||
{%- if cookiecutter.cloud_provider == 'nginx' %}
|
||||
|
||||
web-media:
|
||||
rule: "Host(`{{ cookiecutter.domain_name }}`) && PathPrefix(`/media/`)"
|
||||
entryPoints:
|
||||
- web-secure
|
||||
middlewares:
|
||||
- csrf
|
||||
service: django-media
|
||||
{%- endif %}
|
||||
|
||||
middlewares:
|
||||
redirect:
|
||||
|
@ -59,6 +69,12 @@ http:
|
|||
loadBalancer:
|
||||
servers:
|
||||
- url: http://django:5000
|
||||
{%- if cookiecutter.cloud_provider == 'nginx' %}
|
||||
django-media:
|
||||
loadBalander:
|
||||
servers:
|
||||
- url: http://nginx:80
|
||||
{%- endif %}
|
||||
|
||||
providers:
|
||||
# https://docs.traefik.io/master/providers/file/
|
||||
|
|
|
@ -4,6 +4,9 @@ volumes:
|
|||
production_postgres_data: {}
|
||||
production_postgres_data_backups: {}
|
||||
production_traefik: {}
|
||||
{%- if cookiecutter.cloud_provider == 'nginx' %}
|
||||
production_django_media: {}
|
||||
{%- endif %}
|
||||
|
||||
services:
|
||||
django:{% if cookiecutter.use_celery == 'y' %} &django{% endif %}
|
||||
|
@ -11,6 +14,10 @@ services:
|
|||
context: .
|
||||
dockerfile: ./compose/production/django/Dockerfile
|
||||
image: {{ cookiecutter.project_slug }}_production_django
|
||||
{%- if cookiecutter.cloud_provider == 'nginx' %}
|
||||
volumes:
|
||||
- production_django_media:{{ cookiecutter.project_slug }}/media
|
||||
{%- endif %}
|
||||
depends_on:
|
||||
- postgres
|
||||
- redis
|
||||
|
@ -76,3 +83,14 @@ services:
|
|||
volumes:
|
||||
- production_postgres_data_backups:/backups
|
||||
{%- endif %}
|
||||
{%- if cookiecutter.cloud_provider == 'nginx' %}
|
||||
nginx:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./compose/production/nginx/Dockerfile
|
||||
image: {{ cookiecutter.project_slug }}_local_nginx
|
||||
depends_on:
|
||||
- django
|
||||
volumes:
|
||||
- production_django_media:/usr/share/nginx/media:ro
|
||||
{%- endif %}
|
||||
|
|
Loading…
Reference in New Issue
Block a user