ASCII Smiley Face Daniel Dickinson Mini Headshot
The C Shore

Yet Another Web Server HOWTO

Version 1.0.1~rc2


This is currently in ‘recipe’ format and doesn’t explain why or go into depth. Future plan for this doc is to be more detailed in those areas.

What you get

  • Web Server

    • Static virtual hosting
    • Let’s Encrypt SSl certificates (also used by mail server)
    • Stats virtual host (authorized users only)
  • Admin

    • Some attack reduction and blocking
    • Some stats

Not in this document

Future work

  • Add alternate path for web app support (e.g. CGI, uwSGI, etc), e.g. for webmail

Out of Scope (i.e. Lots of Other Documentation Sources for These)

  • Initial host/instance setup
  • General admin utilities and convenience setup


  • An internet accessible host
  • DNS Service (such as, self-hosted, etc)
  • For this HOWTO: CentOS 7, 1 GiB RAM, 10 GiB HD (e.g. virtual HD)
  • Repos
    • Defaults + EPEL (to install epel do yum install epel-release)


The following packages need to be installed for this setup (e.g. yum install package1 package2 ...)

Admin Tools

  • policycoreutils
  • policycoreutils-python

Web Server

  • httpd-tools
  • lighttpd

Let’s Encrypt / ACME SSL Certificates

  • certbot


  • awstats

Attack Detection / Blocking

  • fail2ban
  • fail2ban-firewalld
  • fail2ban-server

First Steps

  1. Configure networking,admin users etc for your host/instance
  2. (Optional) Install your preferred admin/monitoring utilities etc.
  3. Install “Admin Tools” listed above
  4. Add ‘EPEL’ repository listed above

Web Server & Let’s Encrypt Configuration

If you are not serving web pages or apps, other Certbot configuration might be more suitable for getting Let’s Encrypt SSL certificates for your mail server.

Web Server (HTTP: only serves ACME / Let’s Encrypt verification)

  1. Install “Web Server” packages above
  2. In file /etc/lighttpd/lighttpd.conf

    1. below

      var.vhosts_dir = server_root + "/vhosts"


      var.vhosts_acme_dir = server_root + "/vhosts-acme"
    2. At end, add:

      $HTTP["scheme"] == "http" {
        include "/etc/lighttpd/vhosts-acme.d/*.conf"

  3. Configure IP binding

    1. Uncomment the server.bind = "localhost" line and replace localhost with your hostname (e.g.
    2. Below it add $SERVER["socket"] == "" { }. Optionaly replace with your ipv4 address.
    3. In file, /etc/lighttpd/conf.d/dirlisting.conf
      • set dir-listing.activate to "disable" (unless you want a browse-able list of files and directories for directories without an index file (e.g. index.html, index.htm, etc))
    4. In file /etc/lighttpd/modules.conf

      1. inside the directive server.modules =, uncomment or add the following
        • mod_alias,
        • mod_redirect,
      2. If you want to redirect to, after the closing parentheses for server-modules add

        $HTTP["scheme"] == "http" {
          $HTTP["host"] == "" {
            url.redirect = (".*" => "$0")

      3. Uncomment include "conf.d/compress.conf"

      4. Execute mkdir -p /var/cache/lighttpd/compress

      5. Peform restorecon -Rv /var/cache/lighttpd

    5. For each static virtual host to serve, under /etc/lighttpd/vhosts-acme.d/ include a file such as (NB: The filename must end in .conf):

      $HTTP["host"] == "" {
        var.server_name = "" = server_name
        server.document-root = vhosts_acme_dir + "/"
        accesslog.filename = log_root + "/" + server_name + "/access.log"

    6. Run lighttpd-angel -f /etc/lighttpd/lighttpd.conf and correct any errors detected.

    7. Issue setsebool -P httpd_setrlimit on

    8. In /etc/lighttpd/lighttpd.conf set server.max-connections=512 or set server.max-fd=2048 (depending on traffic and resources)

    9. Make the log directories you pointed to above, e.g. mkdir -p /var/log/lighttpd/

    10. Create an empty log file: e.g. touch /var/log/lighttpd/

    11. Set ownership so lighttpd can write to it: chown -R lighttpd:adm /var/log/lighttpd/

    12. Execute systemctl restart lighttpd

    13. Do systemctl enable lighttpd

Web Server (HTTPS: the real servers; requires SSL)

Prerequisites: Installed and configured web server as above.

Let’s Encrypt (Part 1)

  1. Install “Let’s Encrypt” package above (certbot)
  2. Add certbot user and group

    adduser -U --system -M --home-dir /etc/letsencrypt certbot
    passwd -l certbot
    1. mkdir -p /etc/letsencrypt/renewal-hooks/deploy && chown -R certbot:certbot /etc/letsencrypt
    2. Place the following script in /etc/letsencrypt/renewal-hooks/deploy as lighttpd and make it executable

        cd /etc/letsencrypt/live/${CERTBOT_DOMAIN} && cat fullchain.pem privkey.pem >lighttpd.pem && chmod 640 lighttpd.pem || RET=1
      exit $RET

    3. Place the following script in /etc/cron.daily as certbot and make it executable

      /bin/su -c "certbot -q -n renew" certbot

    4. Issue mkdir -p /var/lib/letsencrypt && chown certbot:certbot /var/lib/letsencrypt

    5. Do mkdir -p /var/log/letsencrypt && chown certbot:adm /var/log/letsencrypt

    6. Perform certbot register

    Lighttpd configuration (Part 2)

    1. Create ACME / Let’s Encrypt verification directories (these will be internet accessible from per-vhost directories down (e.g. in the example below will be the web root)) bash mkdir -p /var/www/vhosts-acme/ chown -R certbot:certbot /var/www/vhosts-acme/
  3. Repeat for each vhost you want to enable

  4. Issue

    firewall-cmd --add-service http
    firewall-cmd --add-service https
    firewall-cmd --runtime-to-permanent

Let’s Encrypt (Part 2)

  1. Issue

    su - certbot
    certbot certonly --staging --webroot -w /var/www/vhosts-acme/ -d -d

  2. If the command completes successfully, repeat the command, without --staging.

    cd /etc/letsencrypt/live/<default-domain>     # In the example above <default-domain> is
    cat fullchain.pem privkey.pem >lighttpd.pem
    chmod 640 lighttpd.pem

Note that Certbot recommendation is to put all hostnames on one certificate (see certbot --help --webroot for more information), unless one has specific reasons for having separate certificates. If you need separate certificates than you will need to issue the commands above for each certificate or set of certificates.

Lighttpd configuration (Part 3)

  1. In /etc/lighttpd/lighttpd.conf, before
    $HTTP["scheme"] == "http" {
      include "/etc/lighttpd/vhosts-acme.d/*.conf"
    which you added previously, add
    SERVER["socket"] == "" { include "ssl.conf" }
    $SERVER["socket"] == "[::]:443" { include "ssl.conf" }
  2. Add a file /etc/lighttpd/ssl.conf that looks like:

    ssl.engine                  = "enable"
    ssl.pemfile                 = "/etc/letsencrypt/live/"
    include "/etc/lighttpd/vhosts.d/*.conf"

  3. And add a file /etc/lighttpd/vhosts.d/ for each virtual host you are adding (in this case; and not including the Radicale vhost), that looks like:

    $HTTP["host"] == "" {
      var.server_name = ""
  = server_name
      server.document-root = vhosts_dir + "/"
      accesslog.filename          = log_root + "/" + server_name + "/access.log"

  4. In file /etc/lighttpd/modules.conf

    1. inside the directive server.modules =, uncomment or add the following

      • "mod_openssl",
    2. And if you want to use HTTP authentication for some pages or sites, also uncomment or add the following

      • "mod_auth",
      • "mod_authn_file",
    3. If you want to redirect HTTP to HTTPS, before

      $HTTP["scheme"] == "http" {
        $HTTP["host"] == "" {
          url.redirect = (".*" => "$0")

    4. which you added above, add

      $HTTP["scheme"] == "http" {
        $HTTP["host"] == "" {
          url.redirect = (".*" => "$0")

    5. and after, add

      $HTTP["scheme"] == "http" {
        $HTTP["url"] !~ "^/.well-known/acme-challenge/" {
          $HTTP["host"] =~ ".*" {
            url.redirect = ( "^/(.*)" => "https://%0/$1" )

  5. If you uncommented/added an mod_auth* line, make sure /etc/lighttpd/conf.d/auth.conf is all commented out

  6. If you want to require HTTP authentication for a page or site

    1. in /etc/vhosts.d/<host-to-require-auth>, above the closing brace (}) in the <host>.conf listed previously, add something similar to:

      auth.backend = "htdigest"
      auth.backend.htdigest.userfile = "/etc/lighttpd/users/<host>"
      auth.require = ( "/" =>
                         "method" => "digest",
                         "realm" => "[auth-realm]",
                         "require" => "valid-user"

    2. Use htdigest to create /etc/lighttpd/users/<host> (man htdigest for details)

    3. Do mkdir -p /var/www/vhosts/ for each static vhost you are creating.

DNS Setup

  • Add a DNS A record for you ‘base hostname’ (e.g. for with ).
  • Add a DNS CNAME record for any virtual hosts (e.g. for add a CNAME record pointing to
  • Your bare domain name (e.g. should be A or AAAA records and not CNAMEs. This also helps if you move some subdomains, or the top level domain and some subdomains to services like Netlify.

Stats Configuration

SELinux Tweaks for AWStats Static Reports

  1. Create a file awstats_cron.te (e.g. in /root) as below

    module awstats_cron 1.0;
    require {
        type httpd_sys_content_t;
        type awstats_t;
        class capability { dac_override dac_read_search };
        class dir search;
        class file { open write getattr ioctl };
    #============= awstats_t ==============
    allow awstats_t httpd_sys_content_t:dir search;
    allow awstats_t httpd_sys_content_t:file { open write getattr ioctl };
    allow awstats_t self:capability { dac_override dac_read_search };

  2. Execute checkmodule -M -m awstats_cron.te -o awstats_cron.mod

  3. Perform semodule_package -o awstats_cron.pp -m awstats_cron.mod

  4. Run semodule -i awstats_cron.pp

AWStats Static Reports

To avoid enabling CGI and therefore increasing attack surface when we are just serving static pages, we generate stats once an hour and put them in <webroot>/awstats and serve them statically.

Lighttpd Configuration

  1. It is recommended that you use HTTP AUTH as described above in your vhost.
  2. You should also add the following to your /etc/lighttpd/vhosts.d/<vhost>.conf file

    alias.url = (
    "/icon/" => "/usr/share/awstats/wwwroot/icon/",
    "/css/" => "/usr/share/awstats/wwwroot/css/",
    "/js/" => "/usr/share/awstats/wwwroot/js/",
    "/classes/" => "/usr/share/awstats/wwwroot/classes/",
    "/awstats-docs/" => "/usr/share/doc/awstats-7.7/"
    1. Make sure that /var/www/vhosts/<hostname>/awstats and /var/www/vhosts/<hostname>/awstats-year exist.
    2. Create /var/www/vhosts/<hostname>/index.html, such as:
      <h2>This Month</h2>
          <li><a href="awstats/"> www stats</a></li>
          <li><a href="awstats/awstats.mail.html"> mail stats</a></li>
      <h2>This Year</h2>
          <li><a href="awstats-year/"> www stats</a></li>
          <li><a href="awstats-year/awstats.mail.html"> mail stats</a></li>

    AWStats Configuration

    1. In /etc/awstats
    2. For web server log stats
      1. cp awstats.localhost.localdomain.conf (assuming your primary hostname is
      2. Set Logfile="/usr/share/awstats/tools/ /var/log/lighttpd/* |"
      3. Set LogFormat = "%host %virtualname %logname %time1 %methodurl %code %bytesd %referrerquot %uaquot"
      4. Set SiteDomain=""
      5. Set HostAliases="" (note you should include any aliases for this host as a space separate listed or look in the docs for how to use regular expressions here)
      6. Set DNSLookup=1
      7. Comment out DirIcons=/awstatsicons
      8. Set TrapInfosForHTTPErrorCodes = "400 403 404 407"
      9. Set ShowHTTPErrorsPageDetail=RH

    Cron Configuration

    1. Replace /etc/cron.hourly/awstats with bash /usr/share/awstats/tools/ -update -configdir="/etc/awstats" -awstatsprog="/usr/share/awstats/wwwroot/cgi-bin/ -dir=/var/www/vhosts/" >/dev/null
  3. And for full stats for the entire year, create /etc/cron.daily/awstats with

    /usr/share/awstats/tools/ -config=mail -update -month=all -configdir="/etc/awstats" -awstatsprog="/usr/share/awstats/wwwroot/cgi-bin/ -dir=/var/www/vhosts/" >/dev/null
    /usr/share/awstats/tools/ -update -month=all -configdir="/etc/awstats" -awstatsprog="/usr/share/awstats/wwwroot/cgi-bin/ -dir=/var/www/vhosts/" >/dev/null
    1. Test updates by running /usr/share/awstats/wwwroot/cgi-bin/ -update

    Attack Detection/Blocking

    1. Install “Attack Detection/Blocking” packages listed above
    2. Create /etc/fail2bain/jail.local like the following:

      port = ssh,<your-alternate-ssh-port-if-applicable>
      filter = sshd-aggressive
      enabled = true
      port = ssh,<your-alternate-ssh-port-if-applicable>
      enabled = true
      enabled = true
      enabled = true

    3. Run touch /var/log/fail2ban.log

    4. And finally execute systemctl enable fail2ban && systemctl start fail2ban