I have got a typical Rails application with Nginx and Mongrel running at http://mydomain. I have to operate a Wordpress blog at http://mydomain.com/blog. My preference is always to host your blog in Apache running on either exactly the same server or perhaps a separate box but I'm not going the consumer to determine another server within the URL. Is the fact that possible and when not, an amount you recommend to complete the aim?

Really, since you are using Nginx, you are already fit and do not need Apache.

You are able to run PHP through fastcgi (you will find good examples of methods to get this done within the Nginx wiki), and employ a URL-matching pattern inside your Nginx configuration to direct some Web addresses to Rails yet others to PHP.

Here's a good example Nginx configuration for managing a WordPress blog through PHP fastcgi (note I have also make the Nginx same as the WordPress .htaccess, so additionally, you will have fancy Web addresses already dealing with this config):

server title  example.com

    charset      utf-8

    error_log    /world wide web/example.com/log/error.log

    access_log   /world wide web/example.com/log/access.log  primary

    root         /world wide web/example.com/htdocs

    include /world wide web/etc/nginx/fastcgi.conf

    fastcgi_index index.php

    # Send *.php to PHP FastCGI on :9001

    location ~ .php$ 

    # You can put another "location" section here to complement some Web addresses and send

    # these to Rails. Or get it done the alternative way and also have "/blog/*" visit PHP

    # first after which anything else visit Rails. Whatever regexes you seem like

    # putting into "location" sections!

    location / Web addresses that do not exist visit WordPress /index.php PHP FastCGI

        if (!-e $request_filename) 


Here's the fastcgi.conf file I am including within the above config (I place it inside a separate file so that all of my virtual host config files may include it in the best place, but it's not necessary to do that):

# joelhardi fastcgi.conf, see http://wiki.codemongers.com/NginxFcgiExample for source

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1

fastcgi_param  SERVER_SOFTWARE    nginx

fastcgi_param  QUERY_STRING       $query_string

fastcgi_param  REQUEST_METHOD     $request_method

fastcgi_param  CONTENT_TYPE       $content_type

fastcgi_param  CONTENT_LENGTH     $content_length

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_title

fastcgi_param  SCRIPT_Title        $fastcgi_script_title

fastcgi_param  REQUEST_URI        $request_uri

fastcgi_param  DOCUMENT_URI       $document_uri

fastcgi_param  DOCUMENT_ROOT      $document_root

fastcgi_param  SERVER_PROTOCOL    $server_protocol

fastcgi_param  REMOTE_ADDR        $remote_addr

fastcgi_param  REMOTE_PORT        $remote_port

fastcgi_param  SERVER_ADDR        $server_addr

fastcgi_param  SERVER_PORT        $server_port

fastcgi_param  SERVER_Title        $server_title

# PHP only, needed if PHP was constructed with --enable-pressure-cgi-redirect

#fastcgi_param  REDIRECT_STATUS    200

I additionally occur to do exactly what the Nginx wiki indicates, and employ spawn-fcgi from Lighttpd as my CGI-spawner (Lighttpd is a nice fast compile w/o strange dependencies, so a fast and simple factor to set up), but you may also make use of a short spend/Perl script for your.