Skip to content

Instantly share code, notes, and snippets.

@iamkingsleyf
Created November 26, 2015 18:09
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 iamkingsleyf/e9a77085c4d9f509a16d to your computer and use it in GitHub Desktop.
Save iamkingsleyf/e9a77085c4d9f509a16d to your computer and use it in GitHub Desktop.
php-fpm nginx wordpress wpsupercache conf
##
# 301 redirect conf
##
server {
listen 80;
server_name healthable.org;
rewrite ^(.*) http://www.healthable.org$1 permanent;
}
##
# Main site config
##
server {
listen 80;
server_name www.healthable.org;
#referer_hash_bucket_size 100;
##
# The magic; HHVM conf
##
#include hhvm.conf;
##
# Logging details
##
access_log /home/kingsley/apps/healthable/logs/access.log;
error_log /home/kingsley/apps/healthable/logs/error.log error;
##
# Web root
##
root /home/kingsley/apps/healthable/public;
##
# Files to serve
##
index index.php index.html;
##
# Redirect server error pages to the static page /50x.html
##
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
#root /usr/share/nginx/html;
#}
##
# Feedburner redirect
##
if ($http_user_agent !~ FeedBurner) {
rewrite ^/feed/ http://feeds.feedburner.com/healthable last;
}
##
# Add a slash at the end of request */wp-admin
##
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
##
# Yoast sitemap
##
location ~ ([^/]*)sitemap(.*)\.x(m|s)l$ {
## this redirects sitemap.xml to /sitemap_index.xml
rewrite ^/sitemap\.xml$ /sitemap_index.xml permanent;
## this makes the XML sitemaps work
rewrite ^/([a-z]+)?-?sitemap\.xsl$ /index.php?xsl=$1 last;
rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
}
##
# Wordpress super cache setup
##
set $cache_uri $request_uri;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $cache_uri 'null cache';
}
if ($query_string != "") {
set $cache_uri 'null cache';
}
# Don't cache uris containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $cache_uri 'null cache';
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
set $cache_uri 'null cache';
}
# Use cached or actual file if they exists, otherwise pass request to WordPress
location / {
try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php ;
}
# Some security settings
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
location ~ /\. { deny all; log_not_found off; access_log off; }
location ~ .php$ {
try_files $uri /index.php;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
}
# Nginx CDN access control
location ~* \.(eot|ttf|otf|woff)$ {
add_header Access-Control-Allow-Origin *;
}
# Set image format types to expire in a very long time
location ~* \.(?:ico|css|js|gif|jpe?g|png|svg|html|xml|otf|ttf|eot|woff)$ {
expires 14d;
access_log off;
add_header Pragma public;
add_header Cache-Control "public";
}
# Cache static files for as long as possible
location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
expires 30d;
log_not_found off;
access_log off;
add_header Cache-Control public;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment