Basic password auth

Updated: 26 March 2024

Create a password file for user mrfoo

sudo htpasswd -c /etc/apache2/.htpasswd mrfoo

In the Virtual Host definition, set the directory for protection and require a valid user

<VirtualHost *:80>
    ServerAdmin chris@christaylordeveloper.co.uk
    ServerName example.com
    DocumentRoot /var/www/example.com/public
    <Directory "/var/www/example.com/public">
        AuthType Basic
        AuthName "Private area"
        AuthUserFile /etc/apache2/.htpasswd
        Require valid-user
    </Directory>
</VirtualHost>

Lighttpd

Updated: 22 October 2023

Install on Ubuntu

sudo apt install lighttpd
# check version
lighttpd -v

Check if lighttpd is running

ps aux | grep lighttpd
# or
systemctl status lighttpd

Basic help

lighttpd --help

Stop the webserver (will restart when system is rebooted)

sudo systemctl stop lighttpd

Start the webserver

sudo systemctl start lighttpd

Prevent lighttbd from starting on system boot

sudo systemctl disable lighttpd

Backup the config file

sudo mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.original.backup
sudo touch /etc/lighttpd/lighttpd.conf

A config for testing

server.document-root = "/var/www/servers/www.example.org/pages/" 
server.port = 3000

# If running lighttpd earlier than lighttpd 1.4.71 add the following:
mimetype.assign = (
  ".html" => "text/html", 
  ".txt" => "text/plain",
  ".jpg" => "image/jpeg",
  ".png" => "image/png" 
)

Check the conf file

lighttpd -tt -f /etc/lighttpd/lighttpd.conf

lighttpd will bind to all interfaces by default and will listen for HTTP requests on the port specified in server.port. lighttpd will then serve files from the server.document-root specified. The files in document root have to be readable by the user starting the web server.

Start the server for testing

lighttpd -D -f lighttpd.conf

Web server log format

Updated: 10 September 2022

Logs to
/var/log/apache2

Use directive
CustomLog ${APACHE_LOG_DIR}/access.log chrisdebug

example

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{Host}i\" \"%{User-agent}i\"" chrisdebug

example

LogFormat "\nNEW ENTRY:\nReferer: \"%{Referer}i\"\nHost: \"%{Host}i\"\nX-Forwarded-Host: \"%{X-Forwarded-Host}i\"\nX-Forwarded-For: \"%{X-Forwarded-For}i\"\nX-Forwarded-Proto: \"%{X-Forwarded-Proto}i\"\nX-Forwarded-Port: \"%{X-Forwarded-Port}i\"" chrisdebug

GoAccess

Updated: 07 July 2024

https://goaccess.io/

GoAccess is an open source real-time web log analyzer and interactive viewer that runs in a terminal in *nix systems or through your browser.


Connect to your webserver via ssh and pipe the access log to goaccess running locally in Docker. Create a report in html format.

ssh user@example.com 'cat /var/log/apache2/the-domain.co.uk.conf/access.log' | \
docker run --rm -i -e LANG=$LANG allinurl/goaccess -a -o html --log-format COMBINED - > report.html

Connect to your webserver via ssh and pipe the access log to goaccess running locally. Create a report in html format.

ssh user@<ip address> 'cat /var/log/apache2/example.com-le-ssl.conf/access.log' | \
goaccess -a -o ~/report.html --log-format=COMBINED --html-report-title="example.com logs" -

Apache

Updated: 27 September 2024

Webserver configuration might be found at

/etc/apache2

Start and stop

sudo service apache2 restart
sudo systemctl reload apache2

Enable and disable a site

sudo a2ensite example.com.conf
sudo a2dissite example.com.conf

Check config

apachectl configtest