Jump to content

Caddy: Difference between revisions

113 bytes added ,  8 July 2023
m
Add code highlighting
imported>Malteneuss
(Fix content error in introduction)
imported>Malteneuss
m (Add code highlighting)
Line 15: Line 15:
</syntaxhighlight>
</syntaxhighlight>


This snippet will let Caddy respond on http://localhost and https://localhost with a dummy text "Hello world!". When no port is mentioned on virtualhost like just "localhost" instead of "localhost:8080", Caddy listens on 80 and 443 by default and redirects requests on 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).


==== Check used ports ====
==== Check used ports ====


To check if Caddy is running and listening as configured you can run netstat:
To check if Caddy is running and listening as configured you can run <code>netstat</code>:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 35: Line 35:
==== Check connection ====
==== Check connection ====


You can use curl to test the http(s) connections:
You can use <code>curl</code> to test the http(s) connections:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 57: Line 57:


Here you can see that Caddy automatically redirects from an unsecure http://localhost to a secure https://localhost call.
Here you can see that Caddy automatically redirects from an unsecure http://localhost to a secure https://localhost call.
For local addresses like "localhost" Caddy always generates and uses a self-signed certificate, which curl correctly doesn't trust; use the "-k" flag to ignore that.
For local addresses like "localhost" Caddy always generates and uses a self-signed certificate, which curl correctly doesn't trust; use the <code>-k</code> flag to ignore that.


== Typical configurations ==
== Typical configurations ==
Anonymous user