Skip to content

Instantly share code, notes, and snippets.

@mauriciogofas
Forked from rahul286/moved.md
Last active February 12, 2016 16:01
Show Gist options
  • Save mauriciogofas/391d0b8c9e2e3e35e1d2 to your computer and use it in GitHub Desktop.
Save mauriciogofas/391d0b8c9e2e3e35e1d2 to your computer and use it in GitHub Desktop.
woo-commerce fastcgi-cache session-conflict solution (attempt)
# WPSINGLE BASIC NGINX CONFIGURATION
server {
server_name woo.rtcamp.net www.woo.rtcamp.net;
access_log /var/log/nginx/woo.rtcamp.net.access.log rt_cache;
error_log /var/log/nginx/woo.rtcamp.net.error.log debug;
root /var/www/woo.rtcamp.net/htdocs;
index index.php index.htm index.html;
fastcgi_cache_use_stale error timeout invalid_header http_500;
set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
if ( $cookie_woocommerce_items_in_cart = "1" ){
set $skip_cache 1;
}
# Don't cache uris containing the following segments
if ($request_uri ~* "(/shop.*|/loja.*|/cart.*|/carrinho.*|/my-account.*|/minha-conta.*|/checkout.*|/finalizar-compra.*|/addons.*|/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $skip_cache 1;
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
set $rt_session "";
if ($http_cookie ~* "wp_woocommerce_session_[^=]*=([^%]+)%7C") {
set $rt_session wp_woocommerce_session_$1;
}
if ($skip_cache = 0 ) {
more_clear_headers "Set-Cookie*";
set $rt_session "";
}
fastcgi_cache_key "$scheme$request_method$host$request_uri$rt_session";
try_files $uri =404;
include fastcgi_params;
fastcgi_pass php;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache WORDPRESS;
fastcgi_cache_valid 60m;
}
include /etc/nginx/common/wpcommon.conf;
include /etc/nginx/common/locations.conf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment