HOW TO configure lighttpd for HTTPS and fast-cgi
This will detail how to configure your owncloud's lighttpd server to use https and fast-cgi. Since my jail only runs owncloud, I am configuring lighttpd to only ever use https.
1. Create a key for your server - I did this is the root's home folder
Code: Select all
cd ~
openssl genrsa -des3 -out server.key 1024
You'll be prompted for a password. Type in one.
OPTIONAL
If you keep the password protection on the key, you will need to enter the password for lighttpd anytime the server starts. I run a headless install, and expect that after a power outage, everything should just work. So - you can remove the password protection from the key with:
Code: Select all
openssl rsa -in server.key -out no.pwd.server.key
2. Create a certificate request, then self-sign the certificate. For this step, it doesn't matter if you removed the password or not.
Code: Select all
openssl req -new -key server.key -out server.csr
Here you get to enter all manner of fun information about your server. The Common Name should match whatever URL you want your sever to present as. It really doesn't matter, though. Next you need to sign the request.
Code: Select all
openssl x509 -req -days 365 -in /root/server.csr -signkey /root/server.key -out /root/server.crt
This creates a certificate (.crt) good for 365 days. Feel free to use any value you want here.
3. Create your pem file. This is the only step that it matters whether or not you removed the password or not.
Code: Select all
cat server.key server.crt > server.pem
The above code will create a pem file that requires a password. If you took the optional step for removing the password, your code is:
Code: Select all
cat no.pwd.server.key server.crt > server.pem
Since the key remains in a place that is only readable by root, it should be fine. If not, it's all in a jail, so no big deal!
4. Move stuff to their destinations, and set ownership & access
Code: Select all
mkdir /usr/local/etc/lighttpd/ssl
cp server.crt /usr/local/etc/lighttpd/ssl
chown -R www:www /usr/local/etc/lighttpd/ssl/
chmod 0600 server.pem
5. Modify the /usr/local/etc/lighttpd/lighttpd.conf file by adding the following anywhere:
Code: Select all
ssl.engine = "enable"
ssl.pemfile = "/root/server.pem"
ssl.ca-file = "/usr/local/etc/lighttpd/ssl/server.crt"
ssl.cipher-list = "ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4-SHA:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM"
ssl.honor-cipher-order = "enable"
ssl.disable-client-renegotiation = "enable"
6. Other modifications to the config file will be done to protect from directory listing. Add the following to lighttpd.conf, anywhere (I used the bottom of the file):
Code: Select all
$HTTP["url"] =~ "^/data/" {
url.access-deny = ("")
}
$HTTP["url"] =~ "^($|/)" {
dir-listing.activate = "disable"
}
cgi.assign = ( ".php" => "/usr/local/bin/php-cgi" )
7. Now we need to personalize the lighttpd config, by supplying the appropriate values for the following variables:
Code: Select all
server.port = 81 #example, you can use other
server.bind = "192.168.1.17"
server.use-ipv6 = "disable" #mandatory, unless you enable ipv6 for all jails
server.document-root = "/usr/local/www/owncloud"
var.server_root = "/usr/local/www/owncloud"
$SERVER["socket"] == "192.168.1.17:81"
8. The next thing is to enable the fast-cgi module. Do this by editing /usr/local/etc/lighttpd/modules.conf, and uncommenting the following line by removing the '#':
9. Edit the /usr/local/etc/lighttpd/conf.d/fastcgi.conf file by adding the following code:
Code: Select all
fastcgi.server = ( ".php" =>
((
"socket" => "/tmp/php.socket",
"bin-path" => "/usr/local/bin/php-cgi",
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "16",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"min-procs" => 1,
"max-procs" => 1,
"idle-timeout" => 20
))
)
10. Edit the lighttpd mime configuration /usr/local/etc/lighttpd/conf.d/mime.conf, and add the following to the list someplace:
Code: Select all
".svg" => "image/svg+xml",
".xht" => "application/xhtml+xml",
".xhtml" => "application/xhtml+xml",
".woff" => "application/x-font-woff",
".svgz" => "image/svg+xml",
We are now done editing conf files (THANK GOODNESS). If you have made a mistake, you can check the config file's syntax with:
Code: Select all
lighttpd -t -f /usr/local/etc/lighttpd/lighttpd.conf
11. Now we are finally ready for Owncloud's installation.
Code: Select all
cd /tmp
fetch http://download.owncloud.org/community/owncloud-5.0.6.tar.bz2
tar xf owncloud-5.0.6.tar.bz2
cp -r /tmp/owncloud /usr/local/www/
chown -R www:www /usr/local/www/
12. You can now start your server with:
Code: Select all
/usr/local/etc/rc.d/lighttpd start
In the example case, I navigate to
https://192.168.1.201:81. There I would create the new user account and password to complete the installation. Click on "Advanced", and click on "MySQL". Type in root for the username, whatever root password you set during the database setup, pick a name for a database (doesn't matter), and leave the localhost part. Click Finish Setup, and ENJOY!!!.