2121 pointsLike some sort of WPMU DEV God"Mindblowingly helpful memberLifetime member
Ovidiu
Member
—
3rd November 2010 (1 year ago)
I am trying to set up nginx as a front end proxy to my apache2 which will continue serving php.
I have it up and ALMOST running with this config gfile: http://pastebin.com/VckwMw03
basically it is a catch all config that works for all vhosts. except for those with multisite enabled :-(
set $site_dir $host; if ($host ~ ^www\.(.*)) { set $site_dir $1; } root /var/www/$site_dir/web;
into something like this: if ($host stripped of www and any subdomains)==zice.ro {rewrite ^.*/files/(.*) /wp-content/blogs.php?file=$1;
if (!-e $request_filename) {
rewrite ^.+?(/wp-.*) $1 last;
rewrite ^.+?(/.*\.php)$ $1 last;
rewrite ^ /index.php last;
} }
basically introducing an exception for this particular domain (which is running WP with multisite and subdomains enabled)
I am trying to set up nginx as a front end proxy to my apache2 which will continue serving php.
I have it up and ALMOST running with this config gfile: http://pastebin.com/VckwMw03
basically it is a catch all config that works for all vhosts. except for those with multisite enabled :-(
set $site_dir $host; if ($host ~ ^www\.(.*)) { set $site_dir $1; } root /var/www/$site_dir/web;
into something like this: if ($host stripped of www and any subdomains)==zice.ro {rewrite ^.*/files/(.*) /wp-content/blogs.php?file=$1;
if (!-e $request_filename) {
rewrite ^.+?(/wp-.*) $1 last;
rewrite ^.+?(/.*\.php)$ $1 last;
rewrite ^ /index.php last;
} }
basically introducing an exception for this particular domain (which is running WP with multisite and subdomains enabled)
I am not sure about what I said above. I reckon that's the way it should work.
as an explanation:
my /var/www/ folder contains:
domain1.tld
domain2.tld
.
.
.
sub.domain1.tld
so this line: set $site_dir $host; if ($host ~ ^www\.(.*)) { set $site_dir $1; } root /var/www/$site_dir/web; checks the right folder, whether www or non-www is accessed. If a sub-domain is accessed that works too.
BUT since multisite subdomains are virtual it must be handled via a rewrite as far as I know.
Please chime in here guys :-)
In this situation we would only use nginx as a reverse-proxy to serve static (or semi-static) content. So no nginx rewrites at all. I'd only get into translating those if we were going to cut apache2 completely out of the equation.
ok, no rewrites. wasn't sure about that. but still, I need to get nginx to not look at subdomains of certain multisite with wildcard enabled domains :-(
its a catchall for all vhosts on my machine so I need to set up an if-clause to catch this one domain and prevent nginx from looking for a sub domain inside /var/www/ as WP handles those virtually and it won't find a physical sub-domain folder!
ok, I figured it out. I have one default nginx config that catches all vhosts except the one that is running wp with subdomains (multisite enabled). that one has its own config file.
It all works but I had to copy these rewrites from here for the wildcard subdomain: http://codex.wordpress.org/Installing_WPMU#Rewriting_Rules_for_others_HTTP_Server btw they still mention blogs.php I changed it to reflect ms-sites.php and all is well.
Now what makes me frown and ask myself if I am wasting my time here is that actually all static content that should have been handled by nginx seems to fall back to apache2 because of this rewrite. am I right?
so basically nginx works as a front end proxy for all vhosts except this one which actually is the biggest one on the server? have I just wasted 3 days getting this to work?
okay I finally got this baby working. quite difficult. if anyone wants any advice on setting up nginx as a friont-end proxy for apache2 ask me. I'm kind of an expert now :-) lol
now seriously, I can give you quite a few hints I had to learn the hard way...
i.e. *.domain.tld is completely different from .domain.tld when it comes to nginx :-(
still struggling with some smaller probs but all in all its working!
another minor problem here: I had set up webmail (squirrelmail) as an alias like this:
Alias /webmail /var/www/webmail/
<Directory "/var/www/webmail/">
Options Indexes FollowSymlinks
AllowOverride None
Order allow,deny
Allow from all
AddDefaultCharset off
</Directory>
<p>so it could be accessed from any domain hosted on my server by appending /webmail to the domain name. I can't get this set up to be taken care of via nginx proxy all I can do is completely bypass nginx for this one and even that doesn't work properly the static content still goes through nginx..</p>
<p>any ideas?
alternatively I will soon post my config files for nginx here...</p>
I have WP super cache running with one of my nginx servers - not switched it on for the new one yet though. There are some new rewrites needed in the config, but they aren't too tricky - I ended up merging about 5 different versions posted around the web and it seems to work quite well.
I'll grab it and post up if you're interested - and when I get on a better connection.
1267 pointsLike some sort of WPMU DEV GodExceptionally helpfulLifetime member
Lifetime member!
—
2nd February 2011 (1 year ago)
#
Followup: Is that configuration compatible with a situation where non-WordPress is also running? For example, a cPanel account with several client accounts, one of which is a WPMU install running Super Cache?
@wpcdn - you would have a different configuration file for each system you are running.
My install has the config files in a sites-available folder. Each config file has a server_name setting which has the domains that the configuration is for - so as an example I have:
1 config file for WP which I've called default and has a server_name of localhost as I want it to be the default configuration I want to use.
1 config file for vanilla forum with the server_name set to support.staypress.com
1 config file for a single WP install (friends) with a server_name set to his domain
1 config file for a codeigniter system with a server_name set to it's domain.
When the request comes in, nginx looks through the server names it knows about and uses that config, otherwise it defaults back to the localhost one.
1267 pointsLike some sort of WPMU DEV GodExceptionally helpfulLifetime member
Lifetime member!
—
3rd February 2011 (1 year ago)
#
Ah, thanks. So, if I'm reading it right, this could still exist under a cPanel account as long as nginx is trained to respond via hostname. As for hosting accounts, this is handled by an nginx WHM plugin that adds a vhost to the config when a user signs up.
Responses (18)
Member — 3rd November 2010 (1 year ago) #
let me add this:
I am not sure about what I said above. I reckon that's the way it should work.
as an explanation:
my /var/www/ folder contains:
domain1.tld
domain2.tld
.
.
.
sub.domain1.tld
so this line:
set $site_dir $host; if ($host ~ ^www\.(.*)) { set $site_dir $1; } root /var/www/$site_dir/web;checks the right folder, whether www or non-www is accessed. If a sub-domain is accessed that works too.BUT since multisite subdomains are virtual it must be handled via a rewrite as far as I know.
Please chime in here guys :-)
Member — 3rd November 2010 (1 year ago) #
hmm.
In this situation we would only use nginx as a reverse-proxy to serve static (or semi-static) content. So no nginx rewrites at all. I'd only get into translating those if we were going to cut apache2 completely out of the equation.
I had this in my Instapaper, hope it helps:
http://www.ubuntugeek.com/using-nginx-as-a-reverse-proxy-to-get-the-most-out-of-your-vps.html
Member — 3rd November 2010 (1 year ago) #
ok, no rewrites. wasn't sure about that. but still, I need to get nginx to not look at subdomains of certain multisite with wildcard enabled domains :-(
If you would please have a look at my config: http://pastebin.com/VckwMw03
its a catchall for all vhosts on my machine so I need to set up an if-clause to catch this one domain and prevent nginx from looking for a sub domain inside /var/www/ as WP handles those virtually and it won't find a physical sub-domain folder!
Member — 4th November 2010 (1 year ago) #
ok, I figured it out. I have one default nginx config that catches all vhosts except the one that is running wp with subdomains (multisite enabled). that one has its own config file.
It all works but I had to copy these rewrites from here for the wildcard subdomain: http://codex.wordpress.org/Installing_WPMU#Rewriting_Rules_for_others_HTTP_Server btw they still mention blogs.php I changed it to reflect ms-sites.php and all is well.
Now what makes me frown and ask myself if I am wasting my time here is that actually all static content that should have been handled by nginx seems to fall back to apache2 because of this rewrite. am I right?
so basically nginx works as a front end proxy for all vhosts except this one which actually is the biggest one on the server? have I just wasted 3 days getting this to work?
Member — 5th November 2010 (1 year ago) #
okay I finally got this baby working. quite difficult. if anyone wants any advice on setting up nginx as a friont-end proxy for apache2 ask me. I'm kind of an expert now :-) lol
now seriously, I can give you quite a few hints I had to learn the hard way...
i.e. *.domain.tld is completely different from .domain.tld when it comes to nginx :-(
still struggling with some smaller probs but all in all its working!
Member — 5th November 2010 (1 year ago) #
Glad you got it working. =)
Member — 7th November 2010 (1 year ago) #
another minor problem here: I had set up webmail (squirrelmail) as an alias like this:
<p>so it could be accessed from any domain hosted on my server by appending /webmail to the domain name. I can't get this set up to be taken care of via nginx proxy all I can do is completely bypass nginx for this one and even that doesn't work properly the static content still goes through nginx..</p>
<p>any ideas?
alternatively I will soon post my config files for nginx here...</p>
Lifetime member! — 31st January 2011 (1 year ago) #
Hi,
Are you using WP Super Cache with your nginx config? I've heard that different settings are needed for that, but I can't find a definitive answer.
Thanks,
Mark
Developer — 31st January 2011 (1 year ago) #
I have WP super cache running with one of my nginx servers - not switched it on for the new one yet though. There are some new rewrites needed in the config, but they aren't too tricky - I ended up merging about 5 different versions posted around the web and it seems to work quite well.
I'll grab it and post up if you're interested - and when I get on a better connection.
Keeper of the Dark Chocolate — 31st January 2011 (1 year ago) #
If you haven;t seen this thread yet, s0omeone offered up their rewrite rules:
http://premium.wpmudev.org/forums/topic/nginx-rewrite-rules-with-wpmu-wp-super-cache-bbpress-and-sitemaps
Developer — 31st January 2011 (1 year ago) #
Yep, those super cache ones look about right to me.
Lifetime member! — 31st January 2011 (1 year ago) #
Thanks. Barry, I'd also love to see yours if you have the time, Otherwise, that other thread should get us going too.
Mark
Lifetime member! — 2nd February 2011 (1 year ago) #
Followup: Is that configuration compatible with a situation where non-WordPress is also running? For example, a cPanel account with several client accounts, one of which is a WPMU install running Super Cache?
Thanks,
Mark
Lifetime member! — 3rd February 2011 (1 year ago) #
To clarify, would these rules work on a situation where you have one account running WPMU, other users running Joomla, some running Magento, etc.
Developer — 3rd February 2011 (1 year ago) #
@wpcdn - you would have a different configuration file for each system you are running.
My install has the config files in a sites-available folder. Each config file has a server_name setting which has the domains that the configuration is for - so as an example I have:
1 config file for WP which I've called default and has a server_name of localhost as I want it to be the default configuration I want to use.
1 config file for vanilla forum with the server_name set to support.staypress.com
1 config file for a single WP install (friends) with a server_name set to his domain
1 config file for a codeigniter system with a server_name set to it's domain.
When the request comes in, nginx looks through the server names it knows about and uses that config, otherwise it defaults back to the localhost one.
Lifetime member! — 3rd February 2011 (1 year ago) #
Ah, thanks. So, if I'm reading it right, this could still exist under a cPanel account as long as nginx is trained to respond via hostname. As for hosting accounts, this is handled by an nginx WHM plugin that adds a vhost to the config when a user signs up.
So it could work, I think.
Thanks!
Lifetime member! — 4th February 2011 (1 year ago) #
Also, how can you tell when the nginx rewrite rules are working properly and serving the Super Cached files correctly?
Lead Developer — 4th February 2011 (1 year ago) #
Look at your page source, super cache tells you if it's a cached page.
Become a member