Despite our love for Ruby we sometimes find ourselves with clients who want to keep their Wordpress blog in conjunction with their shiny new Rails app. The most obvious way to do this is to run it on a different subdomain (blog.domain.com), but this presents an SEO problem because your blog which is often one of the most useful tools for attracting people is now on a different domain.
Use the nginx "location" directive to proxy "/blog" on your domain to your Wordpress server. This method can be used to combine any other external site into your site as well. In this case we set up a rails site like normal but tell it to proxy location /blog to and external ip:port.
server {
listen 80;
server_name www.domain.com;
root /var/www/domain.com/public;
passenger_enabled on;
client_max_body_size 20M;
# Proxy code:
location /blog {
# Use rewrite to remove "/blog" from the url unless you have wordpress hosted as domain.com/blog
rewrite /blog(.*)$ $1 break;
proxy_pass http://50.56.81.59:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
}
}