Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally enable https #15

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
{%- for param, value in extra.items() %}
{{ '{% set ' ~ param ~ ' = "' ~ value ~ '" -%}' }}
{%- endfor %}
# set to True to enable ssl (needs secrets in django_site_secrets state)
{{ '{% set enable_ssl = False %}' }}

# END configurable section

{% raw -%}
{% set home = "/home/" ~ app_name %}
{% set uwsgi_socket = home ~ "/uwsgi.sock" %}
{% set ssl_cert_path = "/etc/nginx/ssl/" ~ app_name ~ "/server.crt" %}
{% set ssl_key_path = "/etc/nginx/ssl/" ~ app_name ~ "/server.key" %}

django_site:
app_name: {{ app_name }}
ssl_cert_path: {{ ssl_cert_path }}
ssl_key_path: {{ ssl_key_path }}
enable_ssl: {{ enable_ssl }}

nginx:
ng:
Expand All @@ -31,17 +42,28 @@ nginx:
- server_name: {{ server_name }}
- listen:
- 80
{%- if enable_ssl %}
- listen 443 ssl
- ssl_certificate: {{ ssl_cert_path }}
- ssl_certificate_key: {{ ssl_key_path }}
{%- endif %}
- location /:
- uwsgi_pass: unix://{{ uwsgi_socket }}
- include: uwsgi_params
- uwsgi_param: UWSGI_SCHEME $http_x_forwarded_proto {# $scheme #}
{#- uncomment if behind load balancer - uwsgi_param: UWSGI_SCHEME $http_x_forwarded_proto #}
- uwsgi_param: SERVER_SOFTWARE nginx/$nginx_version
- location ~ ^/favicon\.(ico|png)$:
- rewrite: (.*) /static/images$1
- location ~ ^/robots\.txt$:
- rewrite: (.*) /static$1
- location /static:
- alias: {{ home }}/static
- location /media:
- alias: {{ home }}/media
{%- if enable_ssl %}
- if ($https = ""):
- rewrite: ^/[a-zA-Z\-]*/admin https://$host$request_uri? permanent
{%- endif %}

users:
{{ app_name }}:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Put your secrets here like

# django_site:
# ssl_key: |
# MYKEY
# ssl_cert: |
# MYCERT

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
base:
'*':
- django_site_secrets
- django_site
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% raw -%}
{% from "nginx/ng/map.jinja" import nginx with context -%}
include:
- memcached
- nginx.ng
Expand All @@ -13,3 +15,24 @@ python3-pip:

python-virtualenv:
pkg.installed

{% if pillar.django_site.get('ssl_cert') -%}
app-{{ pillar.django_site.app_name }}-nginx-cert:
file.managed:
- name: {{ pillar.django_site.ssl_cert_path }}
- makedirs: True
- mode: 660
- user: {{ nginx.lookup.webuser }}
- group: root
- contents_pillar: django_site:ssl_cert

app-{{ pillar.django_site.app_name }}-nginx-key:
file.managed:
- name: {{ pillar.django_site.ssl_key_path }}
- makedirs: True
- mode: 660
- user: {{ nginx.lookup.webuser }}
- group: root
- contents_pillar: django_site:ssl_key
{% endif -%}
{% endraw -%}