• 0

Use WP Super Cache on mobile theme with Nginx


Question

So, this seems to be a rare case. There are people like me who want to use a separate theme for mobile & tablets instead of going the responsive route due to advertisements. I'm currently using Nginx, WP 4.0, WP Super Cache and WordPress Mobile Edition. When using WPME, it makes WPSC create a separate cache entity index-mobile.html, great. But the problem is, the desktop users will be able to see the cached version of the desktop, the mobile users won't for the mobile theme, which will cause a highly negative impact of performance on the servers I'm using. Currently I'm on Media Temple's best Dedicated Server, but even I see it going through a lot of stress. So I need both devices to see HTML.

Currently, Nginx is having all the websites globally use this default configuration that WordPress recommends when using WPSC or W3TC.

 

Source to Nginx vhost settings for WordPress

 

I don't prefer using W3TC, I just couldn't make it work the way I want, and I've been trying to build themes that use features that plugins could do so I could save even more performance, and it's helped. Right now WPSC may be the savior the server needs if I can manage to get the Vhost to also view the mobile cache.

 

I hope someone knows the workaround, because I really don't want a server to get stalled again. I'm currently moving to Digital Ocean to save money while I'm rebuilding my themes. Trying to maintain to 30m visitors a month is stressful.

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

Website link?

 

I don't know much Google landed me on this: https://www.wptouch.com/support/knowledgebase/optimizing-caching-plugins-for-mobile-use/

 

That's meant for optimizing the use of memcache, not for html caching. Basically, what I'm looking or is vhost level modifications where right now the desktop users can see index.html.gz, but I can't do the same for mobile users seeing index-mobile.html.gz, so I have to modify that nginx vhost for WPSC support, that way the mobile users won't see the PHP version, but the HTML version that WordPress Mobile Edition creates. The plugin itself is no longer supported, but JetPack supports it, so it's maintainable.

In the link I priveded in my OP, look for WP Super Cache Rules and that's what may need to be modified in order for mobile users to view the separate cache. I just wish I was an Nginx expert.

Link to comment
Share on other sites

  • 0

Considered a apache tomcat setup?

 

I actually moved away from Apache, because I believe Nginx handles pure HTML and PHP-FPM better than Apache. Nginx was my ace to take advantage of the HTML or HTML.GZ that WPSC creates. At the moment I have Nginx and PHP-FPM making use of all 24 cores, if that makes sense. Right now I have an empty setup on Digital Ocean waiting on my execution.

Link to comment
Share on other sites

  • 0

I actually moved away from Apache, because I believe Nginx handles pure HTML and PHP-FPM better than Apache. Nginx was my ace to take advantage of the HTML or HTML.GZ that WPSC creates. At the moment I have Nginx and PHP-FPM making use of all 24 cores, if that makes sense. Right now I have an empty setup on Digital Ocean waiting on my execution.

Apache and apache tomcat are totally different, tomcat actually caches all the output and only updates cache when necessary, it's very efficient for big websites and used in a lot of big important websites today.
Link to comment
Share on other sites

  • 0

Apache and apache tomcat are totally different, tomcat actually caches all the output and only updates cache when necessary, it's very efficient for big websites and used in a lot of big important websites today.

 

Isn't Tomcat a Java thing though?

 

Edit: I figure it can be used with WordPress, but isn't that overkill? Right now we're only aiming 30m visitors a month or less.

Link to comment
Share on other sites

  • 0

Isn't Tomcat a Java thing though?

Edit: I figure it can be used with WordPress, but isn't that overkill? Right now we're only aiming 30m visitors a month or less.

Hmm even when it's written for java it runs fast with php though, even faster then apache. And it caches the php output and all it's files so it's super fast and not resource heavy.

It's worth looking into in my opinion. I just never had a dedicated server so I could never actually use it myself :/

Link to comment
Share on other sites

  • 0

Hmm even when it's written for java it runs fast with php though, even faster then apache. And it caches the php output and all it's files so it's super fast and not resource heavy.

It's worth looking into in my opinion. I just never had a dedicated server so I could in never actually use it myself :/

 

I get you. On my servers, I'm not only using WordPress, but also Symfony2, so I have so much building up to do on a natural ground, and even WordPress.com uses Nginx, which is why I trust it.

 

There has to be someone who knows how to rewrite with Nginx.  :/ I'd actually hate to start to realize that the answer could be in front of me. $http_user_agent

Link to comment
Share on other sites

  • 0

set $is_mobile ''

if ($http_user_agent ~* (mobi)) {

set $is_mobile '-mobile';

}

location / {

try_files /wp-content/cache/supercache/$http_host/$cache_uri/index$is_mobile.html $uri $uri/ /index.php?$args ;

}

Try something like that in relation to the page you linked, obviously the best fix is a single responsive theme, but if the ads you're running are outdated and won't work with that then obviously it isn't a workable option.
Link to comment
Share on other sites

  • 0
set $is_mobile ''

if ($http_user_agent ~* (mobi)) {
    set $is_mobile '-mobile';
}

location / {
    try_files /wp-content/cache/supercache/$http_host/$cache_uri/index$is_mobile.html $uri $uri/ /index.php?$args ;
}
Try something like that in relation to the page you linked, obviously the best fix is a single responsive theme, but if the ads you're running are outdated and won't work with that then obviously it isn't a workable option.

 

  

Oh wow, I literally just tried setting the variable $mobile into the try_files url, but I'll definitely give that a try as I see the difference. Give me a sec.

 

Edit: I think you have to concatenate the variable like so in order for it to not go through any character-based issue, right?

 

${mobile}

 

Edit #2: Still didn't load the -mobile cache version. What am I missing? :/

Link to comment
Share on other sites

  • 0

It works, but the problem that it didn't work at first was Cloudflare, and I think it's blocking Nginx from detecting the user agent.

Link to comment
Share on other sites

This topic is now closed to further replies.