Skip to content

Instantly share code, notes, and snippets.

@hansohn
Created May 8, 2016 23:34
Show Gist options
  • Save hansohn/34faf7dc673521490ce752f55b633395 to your computer and use it in GitHub Desktop.
Save hansohn/34faf7dc673521490ce752f55b633395 to your computer and use it in GitHub Desktop.
NGINX template for HTTP site with upstream
upstream <site_name>_upstream {
# upstream proxy or socket
server <ip_address:port_number> fail_timeout=0; # proxy
#server unix:/tmp/<site>.socket fail_timeout=0; # socket
}
server {
listen 80;
server_name <server_names> <ip_address>;
root </path/to/root/directory>;
access_log /var/log/nginx/<site_name>_access.log;
error_log /var/log/nginx/<site_name>_error.log;
rewrite_log on;
# allow ff to display fonts from alternate domains
location ~* \.(eot|ttf|woff)$ {
add_header Access-Control-Allow-Origin *;
}
# static asset pipeline
location ~ ^/(assets|images|javascripts|stylesheets|system)/ {
root </path/to/static/assets>;
expires 3M;
break;
}
# forward to upstream
location / {
proxy_pass http://<site_name>_upstream;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment