What's the best way to add a wordpress installation to an existing droplet that is currently running a rails app, so that the Wordpress site is on a subdomain?

December 12, 2014 1.6k views

I have seen ways to do this using Heroku but I'm specifically looking for a simple way to add a blog to my rails app hosted at digitalocean and I want to use Wordpress.


1 Answer

There are a number of different ways this can be done. It partially depends on how you've set up your Rails app. If you aren't already doing so, you'll need to put Nginx or Apache in front of the app as a reverse proxy. This will then be used to direct requests to the correct domain.

Our Rails One-Click application uses Nginx. Using that as a base, you're Nginx configuration would look something like:

server {
    listen   80;
    root /home/rails/public;
    server_name my-domain.com;
    index index.htm index.html;

    location / {
        try_files $uri/index.html $uri.html $uri @app;

    location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
        try_files $uri @app;

     location @app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;

server {
    listen 80;
    server_name blog.my-domain.com;

    root /var/www/html;
    index index.php index.html index.htm;

    location / {
        # try_files $uri $uri/ =404;
        try_files $uri $uri/ /index.php?q=$uri&$args;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;

The key thing to remember is that you must set the server_name correctly for both server blocks.

This tutorial will walk you through the WordPress specific bits like setting up the database:

by Justin Ellingwood
WordPress is the most popular CMS (content management system) in the world. It can be used to get your site or blog off the ground quickly and it provides a nice interface for adding content and modifying the site's design. In this guide, we'll walk through how to install WordPress on Ubuntu 14.04 with an Nginx web server.
Have another answer? Share your knowledge.