Use of variables with an include statement (nginx)
rewrite ^ http://www.example.com$request_uri permanent;
fastcgiparam SCRIPTFILENAME $documentroot$fastcgiscript_name;
But how do you use a variable with an include statement.
When you use Wordpress on Nginx with the W3 Total Cache plugin you need to include the nginx.conf file in the document root:
include /srv/www/example.com/public_html/nginx.conf
Basically you could create one config file for wordpress and include it in the config files in sites-available/ for all your wordpress sites. The one thing I haven't figured out is how to pass a variable to an include statement. The following statements don't work:
include $document_root.'nginx.conf'
include $documentroot$wpnginxconf (where $wpnginx_conf = nginx.conf)
One of the error messages I got is that it couldn't find the file /etc/nginx/$documentroot$wpnginxconf.
So, how can I solve this? Or is there a way around this? Or is this the one statement that I will have to put in the conf files for every wordpress site?
4 Replies
if (!-e $request_filename) {
rewrite ^.+/?(/wp-.*) $1 last;
rewrite ^.+/?(/.*.php)$ $1 last;
rewrite ^(.+)$ /index.php?q=$1 last;
}
I'm hosting about a dozen WordPress blogs and my NginX.conf doesn't have any includes or anything specific to WordPress besides those rewrites I just posted. My nginx.conf is 125 lines with comments. IMO, no need to make something so simple more complex by breaking it into pieces.
That said, unless you're a top-tier blog (ranked in the top 10,000 domains) I bet you don't even need this cache plugin because WordPress has its own cache and Linode+NginX is pretty darn fast.
If that petsmartfeedback site ran WordPress with a few plugins, Linode plus NginX, I bet the CPU would be easily under 50% all day long with no cache plugin. I think you will run out of bandwidth before you run out of Linode CPU power running WordPress on the Linode 512.
Not trying to belittle your site, but I hope you really need that plugin before you go tearing your hair out like I see a lot of people doing with WordPress. You did the right thing moving to Linode + Nginx
In my experience, if a site is slow after moving to Linode, there's probably a serious flaw somewhere and the cache plugin only makes that harder to pinpoint and correct--the slowness is still there, but now only intermittently when the cache is reset.
Before installing a WordPress cache plugin I would try a simpler, more elegant solution--check your my.cnf settings. Install "mysqltuner" and follow the recommendations. Your experience may be different, but when I install MySQL with Fedora, by default the caching is not the best and you can see a huge improvement with very small my.cnf adjustments.
W3TC plugin has its uses. When I first started blogging and adding plugins the page load time increased to 8 seconds. I managed to get it under 2 seconds by removing plugins, replacing some other plugins, and following advice given by YSlow. I just installed W3TC (still on shared hosting) and page load times (using
Will have a look at mysqltuner. Thanx for the tip.