Skip to content

Instantly share code, notes, and snippets.

@Munter
Created May 16, 2013 08:42
Show Gist options
  • Save Munter/5590314 to your computer and use it in GitHub Desktop.
Save Munter/5590314 to your computer and use it in GitHub Desktop.
Nginx example setup for a single page web application with far future expires static content in /static/ and proxying to several backends on any other request that /static or /.
upstream backends {
ip_hash;
server 0.0.0.0:80;
server 0.0.0.0:80;
}
server {
server_name app.falconsocial.com;
listen 80; # ipv4
proxy_read_timeout 3600;
root /var/www;
index index.html index.htm;
error_page 404 /404.html;
error_page 502 /maintenance.html;
error_page 500 502 503 504 /50x.html;
charset utf-8;
location ^~ /static/ {
add_header Cache-Control: max-age=31536000;
# Allow cross origin access
add_header Access-Control-Expose-Headers "Access-Control-Allow-Origin";
add_header Access-Control-Allow-Origin "*";
}
location ^~ /external/ {
add_header Cache-Control "max-age=31536000, must-revalidate";
}
location ~ ^/.+/ {
proxy_pass http://backends;
}
location / {
# Force IE into standards compatibility mode
add_header X-UA-Compatible: "chrome=1;IE=edge"; # Force IE into standards compatible mode
# Cache forever, but always revalidate
add_header Cache-Control "max-age=31536000, must-revalidate";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment