Caddy: Difference between revisions
Cartwatson (talk | contribs) add way to verify configuration is correct |
→Check used ports: Replace deprecated netstat with ss |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 15: | Line 15: | ||
This snippet will let Caddy respond on <code>http://localhost</code> and <code>https://localhost</code> with a dummy text "Hello world!". When no port is mentioned on virtualhost like just <code>localhost</code> instead of <code>localhost:8080</code>, Caddy listens on <code>80</code> and <code>443</code> by default and redirects requests from port 80 (unsecured) to 443 (secured). | This snippet will let Caddy respond on <code>http://localhost</code> and <code>https://localhost</code> with a dummy text "Hello world!". When no port is mentioned on virtualhost like just <code>localhost</code> instead of <code>localhost:8080</code>, Caddy listens on <code>80</code> and <code>443</code> by default and redirects requests from port 80 (unsecured) to 443 (secured). | ||
Use <code>curl localhost | Use <code>curl -iLk localhost</code> to verify the configuration. | ||
For SSL to work, just supply a public domain and ensure HTTP and HTTPS ports are accessible. Caddy will automatically configure TLS: | For SSL to work, just supply a public domain and ensure HTTP and HTTPS ports are accessible. Caddy will automatically configure TLS: | ||
| Line 166: | Line 166: | ||
=== Check used ports === | === Check used ports === | ||
To check if Caddy is running and listening as configured you can run <code> | To check if Caddy is running and listening as configured you can run <code>ss</code>: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="console"> | ||
$ | $ sudo ss --listening --no-queues --numeric --processes --tcp --udp | grep 'Process\|caddy' | ||
Netid State Local Address:Port Peer Address:Port Process | |||
tcp LISTEN 127.0.0.1:2019 0.0.0.0:* users:(("caddy",pid=1000,fd=10)) | |||
tcp | tcp LISTEN *:80 *:* users:(("caddy",pid=1000,fd=11)) | ||
tcp LISTEN *:443 *:* users:(("caddy",pid=1000,fd=12)) | |||
udp UNCONN *:443 *:* users:(("caddy",pid=1000,fd=13)) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
The tcp (ipv4) socket port 2019 is Caddy's management endpoint, for when you want manage its config via web REST calls instead of Nix (ignore). | The tcp (ipv4) socket port 2019 is Caddy's management endpoint, for when you want manage its config via web REST calls instead of Nix (ignore). | ||