Last active
February 19, 2016 16:56
-
-
Save williameliel/87c55b075725acd08e68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FastCGI caching directives | |
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=WORDPRESS:30m inactive=30m; | |
fastcgi_cache_key "$scheme$request_method$host$request_uri"; | |
fastcgi_cache_lock on; | |
fastcgi_cache_use_stale error timeout invalid_header http_500; | |
fastcgi_cache_valid 5m; | |
fastcgi_ignore_headers Cache-Control Expires Set-Cookie; | |
server { | |
##DM - uncomment following line for domain mapping | |
#listen 80 default_server; | |
server_name example.com; | |
##DM - uncomment following line for domain mapping | |
#server_name_in_redirect off; | |
access_log /var/log/nginx/example.com.access.log; | |
error_log /var/log/nginx/example.com.error.log; | |
root /var/www/vhosts/example/production; | |
index index.php; | |
if (!-e $request_filename) { | |
rewrite /wp-admin$ $scheme://$host$uri/ permanent; | |
rewrite ^(/[^/]+)?(/wp-.*) /wp/$2 last; | |
rewrite ^(/[^/]+)?(/.*\.php) /wp/$2 last; | |
} | |
set $no_cache 0; | |
set $why 'huh'; | |
if ($request_method = POST) | |
{ | |
set $no_cache 1; | |
set $why $request_method; | |
} | |
if ($request_uri ~* "/(wp-admin/|wp-login.php)") | |
{ | |
set $no_cache 1; | |
set $why $request_uri; | |
} | |
if ($http_cookie ~* "wordpress_logged_in_") | |
{ | |
set $no_cache 1; | |
set $why $http_cookie; | |
} | |
if ($request_method !~ ^(GET|POST|HEAD)$ ) { | |
return 444; | |
set $why $request_method; | |
} | |
if ($query_string != "") | |
{ | |
set $no_cache 1; | |
} | |
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 $no_cache 1; | |
set $why $request_uri; | |
} | |
include /etc/nginx/fastcgi_params; | |
location / { | |
try_files $uri $uri/ /index.php?$args; | |
} | |
location ~ \.php$ { | |
fastcgi_index index.php; | |
try_files $uri =404; | |
#fastcgi_pass 127.0.0.1:9000; | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
add_header X-Cache $upstream_cache_status; | |
add_header no-X-Cache $no_cache; | |
add_header X-Cache-why $why; | |
fastcgi_cache_bypass $no_cache; | |
fastcgi_no_cache $no_cache; | |
fastcgi_cache WORDPRESS; | |
} | |
location ~ /purge(/.*) { | |
if ($no_cache != 1){ | |
return 403; | |
} | |
fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1"; | |
} | |
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { | |
access_log off; log_not_found off; expires max; | |
} | |
location = /robots.txt { access_log off; log_not_found off; } | |
location ~ /\. { deny all; access_log off; log_not_found off; } | |
server_tokens off; | |
server_name_in_redirect off; | |
} | |
112,1 Bot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment