How To Build Caddy From Source

Updated , by Linode

Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.

Caddy is a fast, open-source and security-focused web server written in Go. Caddy includes modern features such as support for virtual hosts, minification of static files, and HTTP/2. Caddy is also the first web-server that can obtain and renew SSL/TLS certificates automatically using Let’s Encrypt.

Caddy has recently updated their license, clearly defining what is considered personal or enterprise use. A commercial license is now required for commercial or enterprise use, including any installation that uses precompiled Caddy binaries. However, because the project is Apache licensed, by building it from source you have access to the original, Apache-licensed web server.

Build Caddy from Source

Install Go

  1. You will need a current version of Go installed on your Linode. Complete the steps in our guide on installing Go.

  2. Print your Go installation’s current $GOPATH:

     go env GOPATH
    
  3. Set the transitional environment variable for Go modules.

     cd $GOPATH/src
     export GO111MODULE=on
    

Build Caddy

  • To build without plugins:

      go get github.com/caddyserver/caddy/caddy
    
  • To build custom Caddy with plugins:

    1. Create a folder named plugins and add a main.go file with the following contents:

      File: $GOPATH/plugins/main.go
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      
      package main
      
      import (
        "github.com/caddyserver/caddy/caddy/caddymain"
      
        // plug in plugins here, for example:
        // _ "import/path/here"
      )
      
      func main() {
        // optional: disable telemetry
        // caddymain.EnableTelemetry = false
        caddymain.Run()
      }
          
    2. Create a new go module for Caddy:

       go mod init caddy
      
    3. Download and save the packages in $GOPATH/src/<import-path>:

       go get github.com/caddyserver/caddy
      
    4. Install Caddy in $GOPATH/bin:

       go install
      
      Note
      To install Caddy in the current directory you can run go build

Caddy is now installed on your Linode. Read our guide on Installing and Configuring Caddy to learn more about Caddy.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This page was originally published on

Try this guide to receive $100 at signup on a new account.

Your Feedback Is Important

Let us know if this guide made it easy to get the answer you needed.