<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Carl George</title>
    <description>The latest articles on DEV Community by Carl George (@carlwgeorge).</description>
    <link>https://dev.to/carlwgeorge</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F461296%2F029824de-f287-443e-b5e1-2209b73eb943.jpg</url>
      <title>DEV Community: Carl George</title>
      <link>https://dev.to/carlwgeorge</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/carlwgeorge"/>
    <language>en</language>
    <item>
      <title>Getting Started with Caddy (v2) on Fedora</title>
      <dc:creator>Carl George</dc:creator>
      <pubDate>Sat, 19 Sep 2020 06:37:50 +0000</pubDate>
      <link>https://dev.to/carlwgeorge/getting-started-with-caddy-v2-on-fedora-10l8</link>
      <guid>https://dev.to/carlwgeorge/getting-started-with-caddy-v2-on-fedora-10l8</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flkpujkucqoyghx0rs1ma.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flkpujkucqoyghx0rs1ma.png" alt="Caddy logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://caddyserver.com" rel="noopener noreferrer"&gt;Caddy&lt;/a&gt; is an &lt;a href="https://github.com/caddyserver/caddy" rel="noopener noreferrer"&gt;open source&lt;/a&gt; web server that has built-in automatic HTTPS.  I find it easier to use than other web servers where you have to set up HTTPS (automatic or otherwise) separately.  I maintain the caddy package in &lt;a href="https://getfedora.org" rel="noopener noreferrer"&gt;Fedora&lt;/a&gt; to make it more accessible and easier to use.  This guide will demonstrates how to use that package.&lt;/p&gt;

&lt;p&gt;Note: Replace instances of &lt;code&gt;example.com&lt;/code&gt; in this guide with the actual hostname you want to use.&lt;/p&gt;

&lt;h1&gt;
  
  
  Preparation
&lt;/h1&gt;

&lt;p&gt;When you first start Caddy, it will attempt to provision &lt;a href="https://letsencrypt.org" rel="noopener noreferrer"&gt;Let’s Encrypt&lt;/a&gt; certificates for any configured hostnames.  You need to ensure that the appropriate DNS records and network access are in place first so that Caddy can complete the &lt;a href="https://caddyserver.com/docs/automatic-https#acme-challenges" rel="noopener noreferrer"&gt;ACME challenges&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DNS "A" record pointing to your public IPv4 address&lt;/li&gt;
&lt;li&gt;DNS "AAAA" record pointing to your public IPv6 address&lt;/li&gt;
&lt;li&gt;port 80 network access allowed&lt;/li&gt;
&lt;li&gt;port 443 network access allowed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Fedora enables a software firewall by default.  Configure it to allow the necessary access.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firewall-cmd --permanent --add-service http --add-service https
firewall-cmd --reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Caddy v2 is available in the default package repositories for Fedora 33 and newer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dnf install caddy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are using an older Fedora release, RHEL, CentOS, or OpenSUSE, the upstream project has a &lt;a href="https://copr.fedorainfracloud.org/coprs/g/caddy/caddy/" rel="noopener noreferrer"&gt;COPR repository&lt;/a&gt; available to get Caddy v2 packages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Content
&lt;/h2&gt;

&lt;p&gt;Add your own content in &lt;code&gt;/var/www/example.com&lt;/code&gt;, or use this example index file to get started now and swap in your own content later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p /var/www/example.com
echo '&amp;lt;h1&amp;gt;Hello world!&amp;lt;/h1&amp;gt;' &amp;gt; /var/www/example.com/index.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Recursively restore the &lt;a href="https://selinuxproject.org" rel="noopener noreferrer"&gt;SELinux&lt;/a&gt; file context for your content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;restorecon -r /var/www
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configuration
&lt;/h2&gt;

&lt;p&gt;The most common way to configure Caddy is with a &lt;a href="https://caddyserver.com/docs/caddyfile" rel="noopener noreferrer"&gt;Caddyfile&lt;/a&gt;.  The Fedora package includes a Caddyfile as &lt;code&gt;/etc/caddy/Caddyfile&lt;/code&gt;.  The default &lt;a href="https://caddyserver.com/docs/caddyfile/concepts#blocks" rel="noopener noreferrer"&gt;block&lt;/a&gt; serves a welcome page over HTTP only.  In this file, you will need to change the &lt;a href="https://caddyserver.com/docs/caddyfile/concepts#addresses" rel="noopener noreferrer"&gt;address&lt;/a&gt; and the &lt;a href="https://caddyserver.com/docs/caddyfile/directives/root" rel="noopener noreferrer"&gt;site root&lt;/a&gt;.  Aside from the comments, the default Caddyfile looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http:// {
    root * /usr/share/caddy
    file_server
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You need to change it to look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;example.com {
    root * /var/www/example.com
    file_server
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the bare hostname as the address (no protocol) will enable &lt;a href="https://caddyserver.com/docs/automatic-https" rel="noopener noreferrer"&gt;automatic HTTPS&lt;/a&gt; with HTTP to HTTPS redirection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Service
&lt;/h2&gt;

&lt;p&gt;Enable and start the Caddy daemon.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl enable --now caddy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You should now be able to open &lt;a href="https://example.com" rel="noopener noreferrer"&gt;https://example.com&lt;/a&gt; in your browser.  With just that minimal configuration, you get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;automatic certificate provisioning and renewal&lt;/li&gt;
&lt;li&gt;HTTP to HTTPS redirection&lt;/li&gt;
&lt;li&gt;static content served from your content directory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can learn more about Caddy by reading the &lt;a href="https://caddyserver.com/docs/" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;.  You can also ask questions on the &lt;a href="https://caddy.community/" rel="noopener noreferrer"&gt;forum&lt;/a&gt;.  Caddy is a pleasure to use, and I hope you find it as useful as I do.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://commons.wikimedia.org/wiki/File:HTTPS_icon.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fe%2Fe5%2FHTTPS_icon.png" title="Sean MacEntee / CC BY 2.0" alt="HTTPS icon"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webserver</category>
      <category>https</category>
      <category>fedora</category>
      <category>sysadmin</category>
    </item>
  </channel>
</rss>
