jetpack
jetpack copied to clipboard
WP SuperCache not working when moving from http to https
I have WP on ubuntu nginx powered server, everything fine on http but when im moving to https, wp supercache seems not working. Here my nginxwpsc.conf
# WPSC NGINX CONFIGURATION
# DO NOT MODIFY, ALL CHANGES LOST AFTER UPDATE EasyEngine (ee)
set $cache_uri $request_uri;
# POST requests and URL 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 URL containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|wp-.*.php|index.php|/feed/|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 commenter or customer with items in cart
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in|woocommerce_items_in_cart") {
set $cache_uri 'null cache';
}
# Use cached or actual file if they exists, Otherwise pass request to WordPress
location / {
# If we add index.php?$args its break WooCommerce like plugins
# Ref: Automattic/wp-super-cache#330
try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass php;
# Following line is needed by WP Super Cache plugin
fastcgi_param SERVER_NAME $http_host;
}
can someone help to fix this?
This line is wrong:
try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php;
Also you serve cache to your own blog, which is wrong, because preload will not work (WP Super Cahce is not invoked).
Also I suggest to disable WP-CRON: Add define('DISABLE_WP_CRON', true);
to the wp-config.php
and add a cron job to be executed every minute with the correct username: cd /home/UserAccountChangeMe/public_html/ ; php -q wp-cron.php;
.
Does this server
block serves both https and http traffic or only https traffic?
If you serve both:
set $cachefile "/wp-content/cache/supercache/$http_host$cache_uri/index.html";
if ($scheme = https) {
set $cachefile "/wp-content/cache/supercache/$http_host$cache_uri/index-https.html";
}
# Use cached or actual file if they exists, Otherwise pass request to WordPress
location / {
# If we add index.php?$args its break WooCommerce like plugins
# Ref: Automattic/wp-super-cache#330
try_files $cachefile $uri $uri/ /index.php;
}
If you serve only https requests:
# Use cached or actual file if they exists, Otherwise pass request to WordPress
location / {
# If we add index.php?$args its break WooCommerce like plugins
# Ref: Automattic/wp-super-cache#330
try_files /wp-content/cache/supercache/$http_host$cache_uri/index-https.html $uri $uri/ /index.php;
}
In order to make preload to work, add this somewhere above the location
block (but after set $cache_uri $request_uri;
):
# Request from WordPress should always go to PHP, otherwise preload will not work
# Don't forget to change example\.com with your-domain-name\.com and do not delete the '\' before the dot.
if ($http_user_agent ~* ^WordPress.*\ example\.com$ ) {
set $cache_uri 'null cache';
}
I wrote about this problem here: https://github.com/Automattic/wp-super-cache/issues/170
My example Nginx configuration for WP Super Cache: https://github.com/vstoykovbg/nginx.conf-examples/blob/master/wp-super-cache-nginx.conf.md
Also, do not underestimate the favicon.ico problem - if you don't have favicon.ico on every visit the entire WordPress mammoth will be invoked just to tell "there is no such file".
many thanks @vstoykovbg I will try to implement this on my server
Closing this for now because of the lack of activity on this. We can always reopen in the future if needed.