A Caddy config file for PHP Applications

Mattias Geniar shared his Caddyfile – a config file for the high promising Caddy Webserver – for use with a Laravel backed website. His config file takes care of all of these:

  • Redirect all versions of the domain to domain.tld, without the www-prefix
  • Enable gzip compression
  • Store logs in the home dir of the site, rotate them and keep 14 versions
  • Point all PHP requests to an upstream socket, served by php-fpm
  • Redirect all URLs to the index.php (for pretty-printed URLs)
  • Prevent access to files like .htaccess, .git, … (like domain.tld/.htaccess)
  • Set a sane set of default security headers, like HSTS (force HTTPS)

This Caddyfile looks so simple that you could easily take the official php:7.4.1-fpm Docker Image, install Caddy into it and be on your way.

A Caddyfile config example for Laravel →

Published by Bramus!

Bramus is a Freelance Web Developer from Belgium. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.