Configure your Apache to use mod_proxy
Add at the bottom of your Apache configuration file:
ProxyPass /myrailsapp <a href="http://localhost:3000/myrailsapp">http://localhost:3000/myrailsapp</a> ProxyPassReverse /myrailsapp <a href="http://localhost:3000/myrailsapp">http://localhost:3000/myrailsapp</a>
For any more configurations add similar lines, like:
ProxyPass /myrailsapp2 <a href="http://localhost:3001/myrailsapp2">http://localhost:3001/myrailsapp2</a> ProxyPassReverse /myrailsapp2 <a href="http://localhost:3001/myrailsapp2">http://localhost:3001/myrailsapp2</a>
We assume that the Rails project is located at /home/someuser/somepath/myrailsapp.
Put the following in config/lighttpd.conf:
# Start using ./script/server lighttpd
server.port = 3000
server.modules = ( "mod_rewrite", "mod_accesslog", "mod_fastcgi" , "mod_alias" )
server.document-root = "/home/someuser/somepath/myrailsapp/public"
server.event-handler = "freebsd-kqueue"
# this is for FreeBSD!
server.indexfiles = ( "index.html" , "dispatch.fcgi" )
$HTTP["url"] =~ "^/myrailsapp" {
server.document-root = "/home/someuser/somepath/myrailsapp/public"
alias.url = ( "/myrailsapp" => "/home/someuser/somepath/myrailsapp/public" )
accesslog.filename = "/home/someuser/somepath/myrailsapp/log/access.log"
server.error-handler-404 = "dispatch.fcgi"
server.errorlog = "/home/someuser/somepath/myrailsapp/log/lighttpd.error.log"
server.indexfiles = ( "index.html" , "dispatch.fcgi" )
# rails stuff
fastcgi.server = ( ".fcgi" =>
(
(
"socket" => "/home/someuser/somepath/myrailsapp/log/code.socket",
"min-procs" => 2,
"max-procs" => 2,
"bin-path" => "/home/someuser/somepath/myrailsapp/public/dispatch.fcgi",
"bin-environment" => ( "RAILS_ENV" => "development" )
)))
}
mimetype.assign = (
".css" => "text/css",
".gif" => "image/gif",
".htm" => "text/html",
".html" => "text/html",
".jpeg" => "image/jpeg",
".jpg" => "image/jpeg",
".js" => "text/javascript",
".png" => "image/png",
".swf" => "application/x-shockwave-flash",
".txt" => "text/plain"
)
If you have more than one virtual site but keeping all your sockets in one place (like /tmp), you may need to use a different socket filename for each site, so code.socket above may become codea.socket for site1, codeb.socket for site2, etc.
If you want to have more debugging support add this to your lighttpd.conf at the bottom:
## enable debugging debug.log-request-header = "enable" debug.log-response-header = "enable" debug.log-request-handling = "enable" debug.log-file-not-found = "enable"
And in config/environment.rb add at the bottom:
# Include your application configuration below ActionController::AbstractRequest.relative_url_root = '/myrailsapp'
A small note for anyone using Apache 2:
it appears you need to specify a rewrite rule rather than just rely on ProxyPass. The difference between the two is elegantly and succinctly put below (a direct paste from http://www.brainspl.at/articles/trackback/9 )
Apache 1.3.x:
<VirtualHost *:80>
ServerName example.com
ServerAlias <a href="http://www.example.com">www.example.com</a>
ProxyPass / <a href="http://example.com:8000/">http://example.com:8000/</a>
ProxyPassReverse / <a href="http://example.com:8000/">http://example.com:8000/</a>
</VirtualHost>
Apache 2.x:
<VirtualHost *:80>
ServerAdmin <a href="mailto:webmaster@username.tld">webmaster@username.tld</a>
ServerName example.com:80
ProxyRequests Off
ProxyPreserveHost On
RewriteEngine On
RewriteRule ^/(.*) <a href="http://127.0.0.1:3000/">http://127.0.0.1:3000/</a>$1 [P,L]
ProxyPassReverse / <a href="http://127.0.0.1:3000/">http://127.0.0.1:3000/</a>
</VirtualHost>