Commit cf693c50 authored by Emma's avatar Emma

🎉 starting from cc_django_site_setup

parents
- :art: when improving the format/structure of the code
- :rocket: when improving performance
- :pencil2: when improving graphic design
- :book: when writing documentation
- :bulb: new idea
- :bookmark: new release/version
- :construction: work in progress
- :heavy_plus_sign: when adding feature
- :heavy_minus_sign: when removing feature
- :speaker: when adding logging
- :mute: when reducing logging
- :bug: when fixing a bug
- :white_check_mark: when adding tests
- :lock: when dealing with security
- :arrow_up: when upgrading dependencies
- :arrow_down: when downgrading dependencies
{
"user": "me",
"site": "site_name",
"db_host": "",
"db_pass": "",
"secret": "",
"python": ["2", "3"],
"domains": "example.com",
"ip": "194.1.205.53",
"create_certs": ["y", "n"]
}
if [ `which virtualenv|grep virtualenv 2>/dev/null` ]
then
virtualenv -p python{{ cookiecutter.python }} venv
else
python{{cookiecutter.python}} -m venv venv
fi
mv nginx_uwsgi/nginx_site.conf /etc/nginx/sites-available/{{ cookiecutter.site }}
mv nginx_uwsgi/uwsgi_app.ini /etc/uwsgi/apps-available/{{ cookiecutter.site }}.ini
rm -rf nginx_uwsgi
{% if cookiecutter.create_certs == "y" %}
cerbot --nginx -d {{ cookiecutter.domains|join(',') }}
{% endif %}
cd /etc/nginx/sites-enabled
ln -s ../sites-available/{{ cookiecutter.site }} .
cd /etc/uwsgi/apps-enabled
ln -s ../apps-available/{{ cookiecutter.site }}.ini .
{% set main_domain = cookiecutter.domains.split(' ')[0] %}
{% set other_domains = ' '.join(cookiecutter.domains.split(' ')[1:]) %}
server {
listen {{cookiecutter.ip}}:443 ssl http2;
server_name {{ main_domain }};
client_max_body_size 20M;
root /home/{{ cookiecutter.user }}/{{ cookiecutter.site }}/current/;
index index.html;
ssl on;
ssl_certificate /etc/letsencrypt/live/{{main_domain}}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{main_domain}}/privkey.pem;
location /static {
alias /home/{{ cookiecutter.user }}/{{ cookiecutter.site }}/current/static;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/x-javascript text/javascript;
expires 365d;
}
location /uploads {
alias /home/{{ cookiecutter.user }}/{{ cookiecutter.site }}/shared/uploads;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types mage/png image/gif image/jpeg;
expires 365d;
}
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass unix:///var/run/uwsgi/{{ cookiecutter.site }}.sock;
}
}
{% if other_domains|length > 0 %}
server {
listen {{cookiecutter.ip}}:443 ssl;
server_name {{other_domains}};
ssl on;
ssl_certificate /etc/letsencrypt/live/{{main_domain}}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{main_domain}}/privkey.pem;
location / {
rewrite ^/(.*) https://{{main_domain}}/$1;
}
}
{% endif %}
server {
listen {{cookiecutter.ip}}:80;
{% if other_domains|length > 0 %}
# switch comments if using temporary non-ssl site
# server_name {{other_domains}};
{% endif %}
server_name {{cookiecutter.domains}};
location / {
rewrite ^/(.*) https://{{main_domain}}/$1;
}
}
## temporary non-ssl site
# server {
# listen {{cookiecutter.ip}}:443 http2;
# server_name {{main_domain}};
# client_max_body_size 20M;
# root /home/{{ cookiecutter.user }}/{{ cookiecutter.site }}/current/;
# index index.html;
#
# location /static {
# alias /home/{{ cookiecutter.user }}/{{ cookiecutter.site }}/current/static;
# gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/x-javascript text/javascript;
# expires 365d;
# }
#
# location / {
# include /etc/nginx/uwsgi_params;
# uwsgi_pass unix:///var/run/uwsgi/{{ cookiecutter.site }}.sock;
# }
# }
[uwsgi]
master = true
no-orphans = true
autoload = true
socket = /var/run/uwsgi/{{ cookiecutter.site }}.sock
touch-reload = /home/{{ cookiecutter.user }}/{{ cookiecutter.site }}/reload
uid={{ cookiecutter.user }}
gid=www-data
{% if cookiecutter.python == "2" %}
plugin=python
{% else %}
plugin=python3
{% endif %}
chdir = /home/{{ cookiecutter.user }}/{{ cookiecutter.site }}/current
home = /home/{{ cookiecutter.user }}/{{ cookiecutter.site }}/current
virtualenv = /home/{{ cookiecutter.user }}/{{ cookiecutter.site }}/venv
module = wsgi
env = DJANGO_SETTINGS_MODULE=settings
logto = /var/log/uwsgi/app/{{ cookiecutter.site }}.log
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['{{ cookiecutter.domains|replace(' ', "','") }}']
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '{{cookiecutter.secret}}'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
{% if cookiecutter.db_host == "" %}
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, '{{cookiecutter.site}}_db.sqlite3'),
{% else %}
'ENGINE': 'django.db.backends.postgresql',
'NAME': '{{cookiecutter.site}}',
'CONN_MAX_AGE': 5,
'ATOMIC_REQUESTS': True,
'USER': '{{cookiecutter.user}}'
{% if cookiecutter.db_host != "local" %}
'HOST': '{{cookiecutter.db_host}}',
'PASSWORD': '{{cookiecutter.db_pass}}',
{% endif %}
{% endif %}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment