Putting a WordPress blog behind a nginx frontend (with a bit of cheating)

This is how I did a quick fix for a client of ours that are running a Ruby On Rails app behind an nginx/mongrel setup.

The mission where to move their wordpress weblog to the same server as the website.

The easiest way had been to add another IP and install apache behind it. They did not like this solution because they thought they where about to loose google page-rank if the blog and the website where on different ip’s. ok, Fair enough.

The simple solution became to install apache and just proxy the request thought nginx.

proxying with nginx cannot be any easier…. the first try.

Apache is listening on 127.0.0.1:8080 and we want /blog to be proxied to apache.

1
2
3
  location /blog/ {
   proxy_pass       http://127.0.0.1:8080/;
  }

This seemed like a good idea but when apache gets this request the hostname is 127.0.0.1 and wordpress will not like that and will redirect to the host-name that we had setup in wordpress. Just as i write this post i realize that i could just have changed that to 127.0.0.1 and we had been done. 

Sometimes you can’t see the Forest because of the trees… 

I tok me a wile to figure that we where redirected again by wordpress so my solution became this:

1
2
3
4
  location /blog/ {
   proxy_set_header Host www.example.se;
   proxy_pass       http://127.0.0.1:8080/;
}

This make nginx set a Host header with each request so that apache think we are always on the correct host… Even doe we can solve this by setting 127.0.0.1 in wordpress this can be usefull if you have more that one wordpress installation behind nginx .

Happy hacking!

Cheers!

Posted in Hosting at July 3rd, 2008. Trackback URI: trackback Tags: , , , Written by: 
  • http://twitter.com/rockfordal Anders Lundström

    Thank you Thank you Thank you!
    Seems to work

  • https://twitter.com/stjernstrom stjernstrom

    Kul att jag kunde hjälpa till :)

It's past my bedtime is using WP-Gravatar