Caddy: Difference between revisions

imported>Onny
mNo edit summary
imported>Montchr
fix code block formatting resulting in invalid rendered html entities
Line 5: Line 5:
The example snippet below will run Caddy on http://localhost and serving an [http://localhost/example.html example.html] page.
The example snippet below will run Caddy on http://localhost and serving an [http://localhost/example.html example.html] page.


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
<syntaxhighlight lang="nix>
services.caddy = {
services.caddy = {
   enable = true;
   enable = true;
Line 21: Line 21:
   '';
   '';
};
};
</nowiki>}}
</syntaxhighlight>
 
== Configuration examples ==
== Configuration examples ==


Line 28: Line 29:
Caddy will automatically try to acquire SSL certificates for the specified domain, in this example <code>example.org</code>. This requires you to configure the DNS records of your domain correctly, which should point to the address of your Caddy server. The [[firewall]] ports <code>80</code> and <code>443</code> needs to be opened.
Caddy will automatically try to acquire SSL certificates for the specified domain, in this example <code>example.org</code>. This requires you to configure the DNS records of your domain correctly, which should point to the address of your Caddy server. The [[firewall]] ports <code>80</code> and <code>443</code> needs to be opened.


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
<syntaxhighlight lang="nix>
caddy = {
caddy = {
   enable = true;
   enable = true;
Line 42: Line 43:
   '';
   '';
};   
};   
</nowiki>}}
</syntaxhighlight>
 
=== Reverse proxy ===
=== Reverse proxy ===


The following snippet creates a reverse proxy for the domain <code>example.org</code>, redirecting all requests to <code><nowiki>http://10.25.40.6</nowiki></code>
The following snippet creates a reverse proxy for the domain <code>example.org</code>, redirecting all requests to <code><nowiki>http://10.25.40.6</nowiki></code>


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
<syntaxhighlight lang="nix>
caddy = {
caddy = {
   enable = true;
   enable = true;
Line 53: Line 55:
     reverse_proxy http://10.25.40.6
     reverse_proxy http://10.25.40.6
   '';
   '';
};
};
</nowiki>}}
</syntaxhighlight>


=== Redirect ===
=== Redirect ===