Skip to content

Instantly share code, notes, and snippets.

@markjaquith
Created April 19, 2014 17:21
Show Gist options
  • Save markjaquith/11091036 to your computer and use it in GitHub Desktop.
Save markjaquith/11091036 to your computer and use it in GitHub Desktop.
Nginx setup
server {
listen 80;
<% if @use_ssl %>
listen 443 ssl spdy;
ssl_certificate ssl/<%= @domain %>/server.crt;
ssl_certificate_key ssl/<%= @domain %>/server.key;
<% end %>
server_name <%= @domain %><% if @also_www %> www.<%= @domain %><% end %>;
access_log /var/log/nginx/access.log main;
root /srv/www/<%= @path %>;
index index.html index.htm index.php;
include sites-available/custom/<%= @domain %>;
location ~ \.(jpe?g|gif|png|css|bmp|js|ico)$ {
expires 30d;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/nginx-default;
}
location ~ /\.ht[a-z]+$ {
deny all;
}
location ~ \.php$ {
# Set some proxy cache stuff
fastcgi_cache microcache_fpm;
fastcgi_cache_key $scheme$host$request_method$request_uri;
fastcgi_cache_valid 200 5s;
fastcgi_cache_use_stale updating;
fastcgi_max_temp_file_size 1M;
fastcgi_cache_min_uses 3; # Hit a URL 3 times before caching it
set $no_cache_set 0;
set $no_cache_get 0;
set $temp_caching_exemption 0;
if ($request_method !~ ^(GET|HEAD)$) {
set $temp_caching_exemption 1;
}
if ( $temp_caching_exemption = 1 ) {
add_header Set-Cookie "_mcnc=1; Max-Age=10; Path=/";
}
# Bypass cache if no-cache cookie is set
if ( $http_cookie ~* "_mcnc" ) {
set $no_cache_set 1;
set $no_cache_get 1;
}
if ( $http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
set $no_cache_set 1;
set $no_cache_get 1;
}
# fastcgi_no_cache means "Do not store this proxy response in the cache"
fastcgi_no_cache $no_cache_set;
# fastcgi_cache_bypass means "Do not look in the cache for this request"
fastcgi_cache_bypass $no_cache_get;
fastcgi_param PHP_VALUE "newrelic.appname=\"<%= @domain %>;Flatearth\"";
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
try_files $uri =404;
fastcgi_pass phpfpm;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment