Skip to content

Instantly share code, notes, and snippets.

@seanmavley
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanmavley/19bbdf2b796d3c19b7f7 to your computer and use it in GitHub Desktop.
Save seanmavley/19bbdf2b796d3c19b7f7 to your computer and use it in GitHub Desktop.
Optimize content delivery via Nginx
# This decleared upstream app_server is referenced
# below. Its a declare once, use many times kinda thing
upstream app_server {
server 127.0.0.1:9000 fail_timeout=0;
}
# server configurations begins
server {
# Nginx should listen to port 80, which is http
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
# by default root is below
# root /usr/share/nginx/html;
# but we declare our own root directory,
# pointing to where we have our project directory
# the root is important
root /home/portfolio;
# this part isn't really necessary
# Django uses its own template directories
index index.html index.htm;
# http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
client_max_body_size 4G;
# self-explanatory
server_name khophi.co www.khophi.co;
error_log /home/nginx/nginx_error.log warn;
# http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/portfolio/media;
}
# your Django project's static files
location /static {
alias /home/portfolio/static;
}
# Nginx caching of the file extensions listed below.
# Caches for 30days
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 30d;
}
location / {
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; # referencing the app_server above
}
gzip on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types text/plain aplication/xml text/css tex/js text/xml application/x-javascript text/javascript application/javascript application/json application/xml+rss;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment