Monday, February 23, 2009

Configuration lighttpd web server on Iphone V2.2.X

First I had to create a configuration file. I placed this here: /usr/etc/lighttpd.conf and it looks like this:
Code:
#######################################################
### lighttpd.conf BEGIN
#######################################################
#
#### modules to load
server.modules = ( "mod_expire",
"mod_auth",
"mod_access",
"mod_evasive",
"mod_compress",
"mod_status",
"mod_redirect",
"mod_accesslog" )

#### performance options (aggressive timeouts)
server.max-keep-alive-requests = 6
server.max-keep-alive-idle = 15
server.max-read-idle = 15
server.max-write-idle = 15

## single client connection bandwidth limit in kilobytes (0=unlimited)
connection.kbytes-per-second = 0

## global server bandwidth limit in kilobytes (0=unlimited)
server.kbytes-per-second = 0

#### bind to interface (default: all interfaces)
#server.bind = "127.0.0.1"

#### bind to port (default: 80)
server.port = 80

#### run daemon as uid (default: don't care)
#server.username = "nobody"

#### run daemon as gid (default: don't care)
#server.groupname = "nobody"

#### set the pid file (newsyslog)
server.pid-file = "/var/run/lighttpd.pid"

#### name the server daemon publicly displays
server.tag = "lighttpd"

#### static document-root
server.document-root = "/private/var/mobile/Sites/"

#### chroot() to directory (default: no chroot() )
server.chroot = "/"

#### files to check for if .../ is requested
index-file.names = ( "index.html" )

#### disable auto index directory listings
dir-listing.activate = "enable"

#### disable ssl if not needed
ssl.engine = "disable"

#### compress module
compress.cache-dir = "/private/var/tmp/"
compress.filetype = ("text/plain", "text/html", "text/css", "image/png")

#### expire module
expire.url = ( "" => "access plus 6 hours")

#### accesslog module
accesslog.filename = "/var/log/lighttpd/access.log"

#### error log
server.errorlog = "/var/log/lighttpd/error.log"

#### mod_evasive
evasive.max-conns-per-ip = 250

#### limit request method "POST" size in kilobytes (KB)
server.max-request-size = 1

#### disable multi range requests
server.range-requests = "disable"

#### disable symlinks
server.follow-symlink = "disable"

#### ONLY serve files with all lowercase file names
server.force-lowercase-filenames = "disable"

#### mimetype mapping
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" => "application/ogg",
".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",
".cpp" => "text/plain",
".log" => "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",
".bz2" => "application/x-bzip",
".tbz" => "application/x-bzip-compressed-tar",
".tar.bz2" => "application/x-bzip-compressed-tar"
)
#
#######################################################
### lighttpd.conf END
#######################################################
This is a simple configuration and you will want to review it. Change this line:

Code:
server.document-root     = "/private/var/mobile/Sites/"
to reflect the location of your documents. You will also need to create the folder:

Code:
# mkdir /var/log/lighttpd
and change the folders ownership to user nobody:

Code:
# chown nobody:nobody /var/log/lighttpd
so that lighttpd can log events. Next I wanted it to run at startup so I created a plist:

HTML Code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

<dict>
<key>Label</key>
<string>com.http.lighttpd</string>
<key>ProgramArguments</key>

<array>
<string>/usr/sbin/lighttpd</string>
<string>-f</string>
<string>/usr/etc/lighttpd.conf</string>

</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>




and saved it as /Library/LaunchDaemons/com.http.lighttpd.plist

Then I loaded it with the command:

Code:
# launchctl load -w /Library/LaunchDaemons/com.http.lighttpd.plist
and viewed my test html file with Safari. Success!!

EDIT: server.groupname = "nobody"
should be: server.groupname = "nogroup"

but will work either way.

No comments: