Last active
April 20, 2016 05:14
-
-
Save andrea-sdl/338ad1cde3841ffd7ae6 to your computer and use it in GitHub Desktop.
NGINX Wordpress+Memcached Integration Config
This file contains 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
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
location = /robots.txt { | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
location / { | |
# This is cool because no php is touched for static content. | |
# include the "?$args" part so non-default permalinks doesn't break when using query string | |
try_files $uri $uri/ /index.php?$args; | |
} | |
location ~ \.(php)$ { | |
proxy_intercept_errors on; | |
fastcgi_keep_conn on; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
default_type text/html; | |
set $memcached_raw_key $scheme://$host$request_uri; | |
set $memcached_key data-$memcached_raw_key; | |
set $memcached_request 1; | |
if ($request_method = POST ) { | |
set $memcached_request 0; | |
} | |
if ( $uri ~ "/wp-" ) { | |
set $memcached_request 0; | |
} | |
if ( $args ) { | |
set $memcached_request 0; | |
} | |
if ($http_cookie ~* "comment_author_|wordpressuser_|wp-postpass_|wordpress_logged_in_" ) { | |
set $memcached_request 0; | |
} | |
if ( $memcached_request = 1) { | |
memcached_pass 127.0.0.1:11211; | |
error_page 404 = @nocache; | |
break; | |
} | |
fastcgi_pass unix:/run/php/php7.0-fpm.sock; | |
} | |
location @nocache { | |
proxy_intercept_errors on; | |
fastcgi_keep_conn on; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
add_header X-Cache-Engine "not cached"; | |
fastcgi_pass unix:/run/php/php7.0-fpm.sock; | |
} | |
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { | |
expires max; | |
log_not_found off; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment