I\'ve got a standard Rails app with Nginx and Mongrel running at http://mydomain. I need to run a Wordpress blog at http://mydomain.com/blog. My preference would be to host th
Actually, since you're using Nginx, you're already in great shape and don't need Apache.
You can run PHP through fastcgi (there are examples of how to do this in the Nginx wiki), and use a URL-matching pattern in your Nginx configuration to direct some URLs to Rails and others to PHP.
Here's an example Nginx configuration for running a WordPress blog through PHP fastcgi (note I've also put in the Nginx equivalent of the WordPress .htaccess, so you will also have fancy URLs already working with this config):
server {
listen example.com:80;
server_name example.com;
charset utf-8;
error_log /www/example.com/log/error.log;
access_log /www/example.com/log/access.log main;
root /www/example.com/htdocs;
include /www/etc/nginx/fastcgi.conf;
fastcgi_index index.php;
# Send *.php to PHP FastCGI on :9001
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9001;
}
# You could put another "location" section here to match some URLs and send
# them to Rails. Or do it the opposite way and have "/blog/*" go to PHP
# first and then everything else go to Rails. Whatever regexes you feel like
# putting into "location" sections!
location / {
index index.html index.php;
# URLs that don't exist go to WordPress /index.php PHP FastCGI
if (!-e $request_filename) {
rewrite ^.* /index.php break;
fastcgi_pass 127.0.0.1:9001;
}
}
}
Here's the fastcgi.conf file I'm including in the above config (I put it in a separate file so all of my virtual host config files can include it in the right place, but you don't have to do this):
# 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_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
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_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
#fastcgi_param REDIRECT_STATUS 200;
I also happen to do what the Nginx wiki suggests, and use spawn-fcgi from Lighttpd as my CGI-spawner (Lighttpd is a pretty fast compile w/o weird dependencies, so a quick and easy thing to install), but you can also use a short shell/Perl script for that.