WordPress, HTTPS, CDN and W3 Total Cache

by Anthony Somerset on November 11, 2011

I’ve worked with a few sites recently that use HTTPS to secure certain parts of there site and also a couple of pages here are SSL protected due to the data captured. If you use the W3 Total Cache plugin like I do, and I really recommend that you do if you have a wordpress site, and make use of its CDN functionality, you might hit the following snag:

My CDN provider doesnt provide a HTTPS endpoint or its different to my normal CDN URL

the simple solution to this would be, to force loading of cdn assets via HTTP like so:

 

 

 

 

This has one other issue

Why dont i see the Blue/Green Bar?

That’s because your loading HTTP assets on a HTTPS page, for some this is an acceptable tradeoff. but for some this is bar is a must to convey trust to users. Thankfully the solution is fairly simple, Disable the CDN on SSL pages. To disable the CDN on SSL pages only add the following code snippet to your themes functions.php file, this snippet requires the W3TC plugin to be enabled and working to work as its code that tells W3TC: “hey, don’t load the cdn on this page!”

add_action('wp_head','nocdn_on_ssl_page');
function nocdn_on_ssl_page() {
if ($_SERVER['HTTPS'] == "on") {
define('DONOTCDN', true);
}
}

reload an SSL page and watch the address bar and do a view source to see the results!

{ 3 comments }

Nginx and SSL – PHP Redirect Loops

by Anthony Somerset on November 10, 2011

Small post, I’ve been struggling a little with getting ssl to work reliably with https. specifically relating to the following piece of code:

fastcgi_param   HTTPS   on;

Lets wind back, I can get HTTPS working with nginx no problem and the above provided I do the following, maintain 2 vhosts for the same domain, one for http and one for https. The only difference is that the above line is present in the HTTPS vhost’s PHP block.

However thats messy, I either have to maintain 2 vhosts or then deal with extra includes, which just asks for trouble to maintain. Nginx has supported combined HTTP and HTTPS vhosts for some time, so I looked at how I could make this work within a combined vhost. with a little bit of IF magic (yes I know ifisevil) I can add the following to my fastcgi_params file and just forget about it :)

set $ssl off;

if ($ssl_protocol != "" ) {
set $ssl on;
}

fastcgi_param   HTTPS                   $ssl;

Now PHP scripts will correctly detect SSL status and work correctly, no nasty redirect loops (particularly with WordPress) and nice clean vhosts and easy management. Hopefully the great team at Nginx can convert this bit of code into an actual variable in the SSL module which would probably be faster at higher traffic levels

{ 2 comments }

Review: VPS.net

October 31, 2011

Its been a little while so why not start by writing a review as a shameless disclaimer this is motivated by VPS.net’s offer of a free node for life over on there blog, eagle eyed readers may notice that I have previously blogged about them before: http://antsomerset.co.uk/2009/09/29/vps-net-thoughts-and-review-kinda/ http://antsomerset.co.uk/2010/06/22/vps-net-9-months-in/ http://antsomerset.co.uk/2010/09/19/vps-net-san-2-0-early-thoughts/ I’ve used VPS.net in various guises [...]

Read the full article →

Alternative’s to Cpanel: Webmin

June 17, 2011

I’m going to start a mini series of posts here called Alternatives to Cpanel, first you might ask why not Cpanel and its worth pointing out that Cpanel is arguably one of the most popular and most comprehensive control panel solutions for web hosting out there, it might not be good for some people or [...]

Read the full article →

Choosing the Right Host

June 8, 2011

Customer support, or customer failure? A good web host has good customer and technical support departments. People often believe that if their web host offers 24/7 support, their support is good. Often, this is not the case. Why? Put it this way; would you like to be working a night shift with your eyes droopy, [...]

Read the full article →

HOWTO: Upgrade Debian Lenny (5.0) to Debian Squeeze (6.0) on Rackspace Cloud Servers

April 24, 2011

I recently posted on how to update Debian for vps.net servers and its intricacies, I have since been able to document the process for Rackspace and this guide also works for Virtuozzo or OpenVZ VPS’ where you don’t have direct control over the kernel from your VPS so here goes. strong>Disclaimer: please test this yourself [...]

Read the full article →

Is your WordPress site embedding tracking code without your knowledge?

March 21, 2011

I just stumbled upon a couple of important articles relating to the WordPress Stats plugin available for free to all wordpress users and gives a sort of cut down Google Analytics functionality. i found the articles because i was googling as to why all of a sudden my sites were loading a file from quantserve.com, [...]

Read the full article →

HOWTO: Upgrade Debian Lenny (5.0) to Debian Squeeze (6.0) on VPS.net

March 15, 2011

Here are the working upgrade instructions from Lenny to Squeeze (Debian 6) on VPS.net. Disclaimer: please test this yourself first on a NON PRODUCTION SERVER. this may or may not work with other server providers but is specifically tailored to the VPS.net system, I do not guarantee its results outside of my tested system (OnApp [...]

Read the full article →

Email alerts whenever someone logs into root via SSH

October 26, 2010

Want to be notified instantly when someone logs into your server as root? No problem. there was recently a discussion over on the vps.net forums after an incident where a user had had several of there servers logged into as root by an unknown source (since resolved) a helpful user (R4Z0R49) posted this helpful guide [...]

Read the full article →

SSH Root Security Tips

October 16, 2010

ok so i thought i would shove a quick techy thing up while its fresh in my head. this post i think is great when you are in an environment where you have to compromise on security and ease of use. I have to admit though, this tip is not my own i read this [...]

Read the full article →