upstream app_server_djangoapp {
  server localhost:8000 fail_timeout=0;
}

server {
  server_name {{root_domain_name}};
  rewrite ^(.*) https://www.{{root_domain_name}}$1 permanent;
}

server {
  listen 80;
  server_name www.{{root_domain_name}};
  rewrite ^(.*) https://$server_name$1 permanent;
}

server {
  listen       443;
  server_name  www.{{root_domain_name}};

  ssl                  on;
  ssl_certificate      /etc/nginx/{{app_name}}/{{app_name}}.sslchain.crt;
  ssl_certificate_key  /etc/nginx/{{app_name}}/{{app_name}}.key;

#  ssl_session_timeout  5m;

  ssl_protocols  SSLv2 SSLv3 TLSv1;
  ssl_ciphers  HIGH:!aNULL:!MD5;
  ssl_prefer_server_ciphers   on;

  access_log /var/log/nginx/{{root_domain_name}}.access.log;
  error_log /var/log/nginx/{{root_domain_name}}.error.log info;

  keepalive_timeout 5;
  
  # nginx should serve up static files and never send to the WSGI server
  location /static {
    autoindex on; 
    alias {{app_code_dir}}/assets;
  }

  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    if (!-f $request_filename) {
      proxy_pass http://app_server_djangoapp;
      break;
    }
  }
}
