#
# Apache configuration for Samizdat engine - Name-based virtual host
#

# Do not log IP addresses in your access.log
LogFormat "- %l %u %t \"%r\" %>s %b" noip

<VirtualHost *>
    # Replace "samizdat" with FQDN of your site
    ServerName samizdat
    ServerAdmin "webmaster at localhost"

    # Change to a directory where you want to see your log files
    CustomLog /var/log/apache2/samizdat/access.log noip
    # See http://dev.riseup.net/privacy/apache/ for alternatives
    ErrorLog /dev/null

    # Replace "/var/www/samizdat" here and onward with your document
    # root (used to hold site-specific static public files, e.g.
    # favicon)
    DocumentRoot /var/www/samizdat
    <Directory /var/www/samizdat>
        Options FollowSymLinks
        AllowOverride None
        DirectoryIndex dispatch.rb
        RewriteEngine on

        # Don't rewrite requests to static content
        RewriteCond %{REQUEST_URI} ^/(content|css|js)
        RewriteRule .* - [L]

        # Send everything else to dispatch.rb
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ dispatch.rb [QSA,L]
    </Directory>

    # Change "/var/www/samizdat/content/" to wherever you want your
    # uploaded files to be stored. Make sure the directory is writable
    # by web server user (www-data)
    Alias /content/ /var/www/samizdat/content/
    <Directory /var/www/samizdat/content> 
        Options Indexes
        RewriteEngine off
        DirectoryIndex index.html
        <Files *.rb>
            Order deny,allow
            Deny from all
        </Files>
        <LimitExcept GET>
            Order deny,allow
            Deny from all
        </LimitExcept>
    </Directory>

    Alias /css/ /usr/share/samizdat/css/
    Alias /js/ /usr/share/samizdat/js/

    AliasMatch ^/(dispatch)\.rb /usr/share/samizdat/cgi-bin/$1.rb
    <Directory /usr/share/samizdat/cgi-bin>
        Options ExecCGI
        # CGI modules are placed in reverse order of preference, so that
        # the last to succeed overrides previous directives
        <IfModule mod_cgi.c>
            SetHandler cgi-script
        </IfModule>
        <IfModule mod_fastcgi.c>
            SetHandler fastcgi-script
        </IfModule>
        <IfModule mod_fcgid.c>
            SetHandler fcgid-script
        </IfModule>
        <IfModule mod_ruby.c>
            SetHandler ruby-object
            RubyHandler Apache::RubyRun.instance
            RubyRequire apache/ruby-run
        </IfModule>
        <LimitExcept GET POST>
            Order deny,allow
            Deny from all
        </LimitExcept>
    </Directory>
</VirtualHost>

#
# Apache configuration for Samizdat engine - Directory-based site
#

# For each alias, replace the first "/samizdat" below with your site
# location, change "/var/www/samizdat/content/" to wherever you want
# your uploaded files to be stored. Make sure the directory is
# writable by web server user (www-data).
Alias /samizdat/content/ /var/www/samizdat/content/
<Directory /var/www/samizdat/content> 
    Options Indexes
    RewriteEngine off
    DirectoryIndex index.html
    <Files *.rb>
        Order deny,allow
        Deny from all
    </Files>
    <LimitExcept GET>
        Order deny,allow
        Deny from all
    </LimitExcept>
</Directory>

# For each alias below, replace the first "/samizdat" with your site location
Alias /samizdat/css/ /usr/share/samizdat/css/
Alias /samizdat/js/ /usr/share/samizdat/js/

AliasMatch ^/samizdat/(dispatch)\.rb /usr/share/samizdat/cgi-bin/$1.rb
<Directory /usr/share/samizdat/cgi-bin>
    Options ExecCGI
    # CGI modules are placed in reverse order of preference, so that
    # the last to succeed overrides previous directives
    <IfModule mod_cgi.c>
        SetHandler cgi-script
    </IfModule>
    <IfModule mod_fastcgi.c>
        SetHandler fastcgi-script
    </IfModule>
    <IfModule mod_fcgid.c>
        SetHandler fcgid-script
    </IfModule>
    <IfModule mod_ruby.c>
        SetHandler ruby-object
        RubyHandler Apache::RubyRun.instance
        RubyRequire apache/ruby-run
    </IfModule>
    <LimitExcept GET POST>
        Order deny,allow
        Deny from all
    </LimitExcept>
</Directory>

# Site root location and directory, used to store static public files
Alias /samizdat/ /var/www/samizdat/
<Directory /var/www/samizdat>
    Options FollowSymLinks
    AllowOverride None
    DirectoryIndex dispatch.rb
    RewriteEngine on

    # Don't rewrite requests to static content
    RewriteCond %{REQUEST_URI} ^/samizdat/(content|css|js)
    RewriteRule .* - [L]

    # Send everything else to dispatch.rb
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ dispatch.rb [QSA,L]
</Directory>
