|
||||||||||||||||||||||
|
||||||||||||||||||||||
December 21, 2006 Here's a how-to to show you how to run a local (development mode) Rubyonrails application using Lighttpd proxied under an Apache vhost on Mac OS X. You can use this same configuration in a production environment with a few minor changes. First, make some directories in your home directory. The Lighttpd process will run as your user and will live in your home directory, logs, pids and all. You might consider making a seperate system user for this, but I didn't. cd mkdir bin etc log var Next you will need some Lighttpd control scripts. These scripts will make restarting Lighttpd a snap: > cat bin/start-lighttpd.sh #!/bin/sh # a space-delimited, quoted list of strings RAILS_APPS=("depot") for RAILS_APP in ${RAILS_APPS[@]}; do echo "Starting RAILS_APP: ${RAILS_APP}" chmod 777 ~/rails/${RAILS_APP}/public \ ~/rails/${RAILS_APP}/log lighttpd -f ~/etc/lighttpd-${RAILS_APP}.conf done
> cat bin/stop-lighttpd.sh #!/bin/sh echo "Killing lighttpd instances owned by destiney" killall -u destiney lighttpd 2>&1
> cat bin/restart-lighttpd.sh #!/bin/sh ~/bin/stop-lighttpd.sh ~/bin/start-lighttpd.sh Here's a simple lighttpd configuration. It will use port 3001 and will point to my Rubyonrails depot app I built while reading Agile Web Development with Rails. > cat etc/lighttpd-depot.conf |grep -v ^#|grep -v ^$ server.modules = ( "mod_rewrite", "mod_redirect", "mod_access", "mod_auth", "mod_fastcgi", "mod_cgi", "mod_compress", "mod_proxy", "mod_accesslog" ) server.port = 3001 server.document-root = "~/rails/depot/public/" fastcgi.server = ( ".fcgi" => ( "localhost" => ( "socket" => "~/var/lighttpd-fcgi-depot.socket", "bin-path" => "~/rails/depot/public/dispatch.fcgi", "bin-environment" => ( "RAILS_ENV" => "development" ), "min-procs" => 1, "max-procs" => 1, "idle-timeout" => 60, "allow-x-send-file" => "enable" ) ) ) server.errorlog = "~/log/lighttpd_error_log-depot" server.indexfiles = ( "index.php", "index.html", "index.htm", "default.htm" ) server.pid-file = "~/var/lighttpd-depot.pid" server.dir-listing = "disable" server.error-handler-404 = "/dispatch.fcgi" mimetype.assign = ( ".pdf" => "application/pdf", ".sig" => "application/pgp-signature", ".spl" => "application/futuresplash", ".class" => "application/octet-stream", ".ps" => "application/postscript", ".torrent" => "application/x-bittorrent", ".dvi" => "application/x-dvi", ".gz" => "application/x-gzip", ".pac" => "application/x-ns-proxy-autoconfig", ".swf" => "application/x-shockwave-flash", ".tar.gz" => "application/x-tgz", ".tgz" => "application/x-tgz", ".tar" => "application/x-tar", ".zip" => "application/zip", ".mp3" => "audio/mpeg", ".m3u" => "audio/x-mpegurl", ".wma" => "audio/x-ms-wma", ".wax" => "audio/x-ms-wax", ".ogg" => "audio/x-wav", ".wav" => "audio/x-wav", ".gif" => "image/gif", ".jpg" => "image/jpeg", ".jpeg" => "image/jpeg", ".png" => "image/png", ".xbm" => "image/x-xbitmap", ".xpm" => "image/x-xpixmap", ".xwd" => "image/x-xwindowdump", ".css" => "text/css", ".html" => "text/html", ".htm" => "text/html", ".js" => "text/javascript", ".asc" => "text/plain", ".c" => "text/plain", ".conf" => "text/plain", ".text" => "text/plain", ".txt" => "text/plain", ".dtd" => "text/xml", ".xml" => "text/xml", ".mpeg" => "video/mpeg", ".mpg" => "video/mpeg", ".mov" => "video/quicktime", ".qt" => "video/quicktime", ".avi" => "video/x-msvideo", ".asf" => "video/x-ms-asf", ".asx" => "video/x-ms-asf", ".wmv" => "video/x-ms-wmv" ) url.access-deny = ( "~", ".inc" ) Here is the Apache vhost and proxy stuff. Repeat and increment the port assignment for each additional Rails app + vhost combination you setup. NameVirtualHost 127.0.0.1 <VirtualHost 127.0.0.1> ProxyRequests On ProxyVia On ProxyPass / http://127.0.0.1:3001/ ProxyPassReverse / http://127.0.0.1:3001/ ServerName depot </VirtualHost> > sudo apachectl restart You can use the Mac OS Netinfo Manager to add a host entry to your system, but putting a line in /etc/hosts works easy enough for me. echo "127.0.0.1 depot" >> /etc/hosts At this point you should be able to start Lighttpd using ~/bin/start-lighttpd.sh and browse to http://depot. Have fun!
|
|
|||||||||||||||||||||
|
||||||||||||||||||||||