Jump to content

Caddy: Difference between revisions

→‎Reverse proxy: Add example on forward real client ip
imported>Jeyemwey
m (fix: closing code tag)
(→‎Reverse proxy: Add example on forward real client ip)
 
(6 intermediate revisions by 3 users not shown)
Line 4: Line 4:
== Get started ==
== Get started ==


To try out Caddy add the following minimal example to your [https://nixos.wiki/wiki/NixOS_modules NixOS module]:
To try out Caddy add the following minimal example to your [[NixOS modules | NixOS module]]:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 100: Line 100:
   '';
   '';
};
};
</syntaxhighlight>
</syntaxhighlight>In case you would like to forward the real client IP of the request to the backend, add following headers<syntaxhighlight lang="nix">
 
services.caddy = {
* [https://caddyserver.com/docs/quick-starts/reverse-proxy Caddy reverse proxy documentation]
  virtualHosts."example.org".extraConfig = ''
    reverse_proxy http://10.25.40.6 {
      header_down X-Real-IP {http.request.remote}
      header_down X-Forwarded-For {http.request.remote}
    }
  '';
};
</syntaxhighlight>Fur further reverse proxy configuration, see [https://caddyserver.com/docs/quick-starts/reverse-proxy upstream documentation].


=== Redirect ===
=== Redirect ===
Line 115: Line 122:
       redir https://www.example.org{uri}
       redir https://www.example.org{uri}
   '';
   '';
     serverAlias = [ "old.example.org" ];
     serverAliases = [ "old.example.org" ];
};
};
</syntaxhighlight>
</syntaxhighlight>
Line 206: Line 213:


[[Category:Applications]]
[[Category:Applications]]
[[Category:Web Servers]]
[[Category:Server]]
[[Category:Networking]]
63

edits