Caddy (web server): Difference between revisions
Created page with "* [https://caddyserver.com/ Website] This article is about Caddy v2." |
No edit summary |
||
| (12 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
* [https://caddyserver.com/ Website] | * [https://caddyserver.com/ Website] | ||
Caddy is a webserver with automatic HTTPS and modern defaults (e.g. http2, websocket support). | |||
This article is about Caddy v2. | This article is about Caddy v2. | ||
Note that caddy does not support <code>.htaccess</code> which is only supported in Apache. | |||
==Caddyfile== | |||
===Reverse Proxy=== | |||
Just use the [https://caddyserver.com/docs/caddyfile/directives/reverse_proxy reverse_proxy] directive. | |||
By default, this will automatically preserve headers. | |||
Things like websockets will work automatically. | |||
<pre> | |||
gitlab.example.com { | |||
encode zstd gzip | |||
reverse_proxy localhost:8001 | |||
} | |||
</pre> | |||
====To HTTPS==== | |||
If you are reverse proxying to another HTTPS, you may need to specify the SNI as follows: | |||
<pre> | |||
dev2.davidl.me { | |||
reverse_proxy https://192.168.1.41 { | |||
transport http { | |||
tls_server_name dev2.davidl.me | |||
} | |||
} | |||
} | |||
</pre> | |||
* Try this if you get <code>502</code> errors. | |||
===Only Local=== | |||
<pre> | |||
@localnet remote_ip 127.0.0.1 192.168.0.0/16 | |||
@notlocalnet not remote_ip 127.0.0.1 192.168.0.0/16 | |||
</pre> | |||
==PHP== | |||
# Install <code>php-fpm</code> | |||
# Modify <code>/etc/php/7.4/fpm/pool.d/www.conf</code> to listen on a socket or port (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== | |||
Experimental HTTP3 support can be enabled by adding the following to your Caddyfile.<br> | |||
Note that HTTP3/QUIC uses UDP which needs to be allowed in your firewall and port forwarded through any NATs.<br> | |||
<pre> | |||
{ | |||
servers { | |||
protocol { | |||
experimental_http3 | |||
} | |||
} | |||
} | |||
</pre> | |||