Caddy (web server): Difference between revisions

From David's Wiki
No edit summary
Line 25: Line 25:
}
}
</pre>
</pre>
==PHP==
# Install <code>php-fpm</code>
# Modify <code>/etc/php/7.4/fpm/pool.d/www.conf</code> to listen on a socket (e.g. 9000)
<pre>
example.com {
  root * /var/www/wordpress
  encode zstd gzip
  php_fastcgi unix//run/php/php-version-fpm.sock
  file_server
}
</pre>
Notes
* If you prefer to use a UNIX socket, you can use <code>php_fastcgi unix//var/run/php/php7.4-fpm.sock</code>


===HTTP3===
===HTTP3===

Revision as of 14:29, 28 January 2021

Caddy is a webserver which is much simpler to configure than Apache and is supposedly just as fast. It handles HTTPS automatically.

Advantages of Caddy:

  • Much simpler configuration with sane defaults (e.g. no directory listing).
  • Automatic HTTPS (redirect, public certificates, self-signed certificates)
  • Automatic HTTP/2

This article is about Caddy v2.

Note that caddy does not support .htaccess which is only supported in Apache.

Caddyfile

Reverse Proxy

Just use the reverse_proxy directive.
By default, this will automatically preserve headers.
Things like websockets will work automatically.

gitlab.example.com {
  encode zstd gzip
  reverse_proxy localhost:8001
}

PHP

  1. Install php-fpm
  2. Modify /etc/php/7.4/fpm/pool.d/www.conf to listen on a socket (e.g. 9000)
example.com {
  root * /var/www/wordpress
  encode zstd gzip
  php_fastcgi unix//run/php/php-version-fpm.sock
  file_server
}

Notes

  • If you prefer to use a UNIX socket, you can use php_fastcgi unix//var/run/php/php7.4-fpm.sock

HTTP3

Add the following to your Caddyfile:

{ 
  servers {
    protocol {
      experimental_http3
    }
  }
}