Skip to content

Instantly share code, notes, and snippets.

@jalp
Last active October 16, 2017 08:58
Show Gist options
  • Save jalp/9093810 to your computer and use it in GitHub Desktop.
Save jalp/9093810 to your computer and use it in GitHub Desktop.
Nginx configuration for ssl redirection and serving API through gunicorn server
#user nobody;
worker_processes 1;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include 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"';
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
# Gunicorn app server
upstream app_server {
server localhost:8000 fail_timeout=0;
}
# Redirect to https
server {
listen 80 default;
server_name localhost;
return 301 https://$host$request_uri;
}
# HTTPS server configuration
server {
listen 443 ssl;
server_name localhost;
ssl on;
ssl_certificate /Users/jalp/Documents/Repositories/Propio/certs/dummy-cert.pem;
ssl_certificate_key /Users/jalp/Documents/Repositories/Propio/certs/dummy-key.pem;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
# full path to the project dir - the dir that contains the urls.py file
root /Users/jalp/Documents/Repositories/Propio/apilogger/apilog;
access_log /opt/bvp/log/nginx_access.log;
error_log /opt/bvp/log/nginx_error.log;
location / {
try_files $uri $uri/ @gunicorn-apilogger;
}
location @gunicorn-apilogger {
# an HTTP header important enough to have its own Wikipedia entry:
# http://en.wikipedia.org/wiki/X-Forwarded-For
# Sending client IP address to web server
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_connect_timeout 10;
proxy_read_timeout 10;
# we don't want nginx trying to do something clever with
# redirects, we set the Host: header above already.
proxy_redirect off;
# Gunicorn server
proxy_pass http://app_server;
}
# Rest framework static data
location /static/ {
# Dirty solution but... it works :)
root /Users/jalp/Virtualenvs/Propio/prueba/lib/python2.7/site-packages/rest_framework;
}
# Deny access to .files
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
# Disable favicon annoying request
location = /favicon.ico {
log_not_found off;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment