Skip to content

Instantly share code, notes, and snippets.

@nmfzone
Last active October 27, 2020 06:27
Show Gist options
  • Save nmfzone/009feb9635c8b86f9d1c8bb7ac3de4e6 to your computer and use it in GitHub Desktop.
Save nmfzone/009feb9635c8b86f9d1c8bb7ac3de4e6 to your computer and use it in GitHub Desktop.
NginX Config for Django + Flower + Letsencrypt
location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
root /var/www/letsencrypt; # make sure you create this directory
}
server {
listen 80;
listen [::]:80;
server_name flower.app.com;
include /etc/nginx/snippets/letsencrypt.conf;
# Redirect http://flower.app.com to https://flower.app.com
location / {
return 301 https://flower.app.com$request_uri;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name flower.app.com;
ssl_certificate /etc/letsencrypt/live/flower.app.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/flower.app.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/flower.app.com/fullchain.pem;
include /etc/nginx/snippets/ssl.conf;
location / {
include proxy_params;
proxy_pass http://localhost:5001; # change port based on your flower port
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 80;
listen [::]:80;
server_name app.com;
include /etc/nginx/snippets/letsencrypt.conf;
# Redirect http://app.com to https://app.com
location / {
return 301 https://app.com$request_uri;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
root /var/www/html/app;
server_name app.com;
ssl_certificate /etc/letsencrypt/live/app.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/app.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/app.com/fullchain.pem;
include /etc/nginx/snippets/ssl.conf;
location / {
include proxy_params;
proxy_pass http://unix:/tmp/django-app-com.sock;
}
location /static/ {
root /var/www/app/public;
}
}
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
# OCSP Stapling ---
# fetch OCSP records from URL in ssl_certificate and cache them
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security "max-age=15768000; includeSubdomains; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
@nmfzone
Copy link
Author

nmfzone commented Oct 27, 2020

To run the Django App, use the config from here:

https://gist.github.com/nmfzone/3dd8207bc8c56ad9a75bcdf1059ca45e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment