Skip to content

Instantly share code, notes, and snippets.

@mtellezj
Created August 7, 2017 23:46
Show Gist options
  • Save mtellezj/7dfa1f58bed1c570815460c447601246 to your computer and use it in GitHub Desktop.
Save mtellezj/7dfa1f58bed1c570815460c447601246 to your computer and use it in GitHub Desktop.
Config file for nginx with http and https support
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
upstream app {
server django:5000;
}
server {
listen 80;
charset utf-8;
server_tokens off;
location / {
return 301 https://$host$request_uri;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
}
server {
client_max_body_size 8M;
location /media/ {
alias /media/;
try_files $uri @proxy_to_app;
}
listen 443;
ssl on;
ssl_certificate /etc/ssl/certs/my_hostname.com.mx.crt;
ssl_certificate_key /etc/ssl/private/my_hostname.com.mx.key;
server_name my_hostname.com.mx;
location / {
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
# checks for static file, if not found proxy to app
try_files $uri @proxy_to_app;
}
# cookiecutter-django app
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment