Skip to content

Instantly share code, notes, and snippets.

@Flyingmana
Created March 25, 2012 22:25
Show Gist options
  • Save Flyingmana/2200407 to your computer and use it in GitHub Desktop.
Save Flyingmana/2200407 to your computer and use it in GitHub Desktop.
configure owncloud under yaws - webserver
yaws_404_to_index_php.erl is the src for a custom 404 errormod.
This error mod executes the request with index.php in docroot, if the requests file does not exist in filesystem.
This code only works with php configured as cgi, but sure could easy extended to support fcgi, too.
You compile this with 'erlc' and have to place it in the ebin directory of yaws.
For more information look at http://yaws.hyber.org/ and https://github.com/klacke/yaws
In the config the "dir_listings = false" is important and also the redirect from "/data" to somewhere else, because files will be saved in this directory and it should not be accessable from the outside.
%%%----------------------------------------------------------------------
%%% File : 404_to_index_php.erl
%%% Author : Daniel Fahlke <[email protected]>
%%% Purpose :
%%% Created : 28 Jan 2010 by Daniel Fahlke <[email protected]>
%%%----------------------------------------------------------------------
-module(yaws_404_to_index_php).
-author('[email protected]').
-include("yaws/include/yaws.hrl").
-include("yaws/include/yaws_api.hrl").
-export([out404/1,
out404/3,
crashmsg/3]).
%% The default error 404 error delivery module
%% This function can be used to generate
%% a special page on 404's (it doesn't even have to be a 404)
out404(Arg) ->
out404(Arg, get(gc), get(sc)).
out404(Arg, GC, SC) ->
yaws_cgi:call_cgi(Arg, element(2,SC#sconf.php_handler), lists:flatten(Arg#arg.docroot) ++ "/index.php").
%% possibility to customize crash messages,
%% while developing
%% it's extremely convenient to get the crash messages in the browser,
%% however not in production :-)
%% This function can only return an {ehtml, EH} or an {html, HTML}
%% value, no status codes, no headers etc.
crashmsg(_Arg, _SC, L) ->
{ehtml,
[{h2, [], "Internal error, yaws code crashed"},
{br},
{hr},
{pre, [], L},
{hr}]}.
<server owncloud.myserver.com/>
port = 80
listen = 0.0.0.0
docroot = /var/www/owncloud/src
allowed_scripts = php
php_handler = <cgi, /usr/local/bin/php-cgi>
errormod_404 = yaws_404_to_index_php
access_log = false
dir_listings = false
<redirect>
/data == /
</redirect>
</server>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment