如何在Ubuntu 18.04上使用Caddy托管网站

介绍 (Introduction)

Caddy is a web server designed around simplicity and security that comes with a number of features that are useful for hosting websites. For example, it can automatically obtain and manage TLS certificates from Let’s Encrypt to enable HTTPS, and includes support for HTTP/2. HTTPS is a system for securing traffic between your users and your server, and is quickly becoming a basic expectation of any website running in production — without it, Chrome and Firefox will warn that your website is “Not Secure” if users try to submit login information.

Caddy是一款基于简单性和安全性而设计的Web服务器,具有许多可用于托管网站的功能。 例如,它可以从Let's Encrypt自动获取和管理TLS证书以启用HTTPS,并包括对HTTP / 2的支持。 HTTPS是一种用于保护用户与服务器之间的流量的系统,并且正Swift成为生产环境中运行的任何网站的基本要求-如果没有HTTPS,Chrome和Firefox将警告用户如果您尝试提交登录名,则您的网站“不安全”信息。

Previously, the recommended method for installing Caddy was to download pre-built binaries from the Caddy project website. However, changes in how Caddy’s licensing works means that you’re no longer allowed to use these pre-built binaries for commercial purposes unless you pay a license fee, even if you’re just using Caddy internally within a business. Luckily, the Caddy source code is still fully open-source and you can build Caddy yourself to avoid running into licensing issues.

以前,推荐的安装Caddy的方法是从Caddy项目网站下载预构建的二进制文件。 但是,Caddy许可工作方式的变化意味着,除非您支付许可费,否则就不再允许将这些预制的二进制文件用于商业目的,即使您只是在企业内部使用Caddy也不例外。 幸运的是,Caddy源代码仍然是完全开源的,您可以自己构建Caddy以避免遇到许可问题。

In this tutorial, you’ll build Caddy from source and use it to host a website secured with HTTPS. This entails compiling it, configuring it using a Caddyfile and installing plugins. In the end, you’ll learn how to upgrade your installation when a new version is released.

在本教程中,您将从源代码构建Caddy,并将其用于托管使用HTTPS保护的网站。 这需要对其进行编译,使用Caddyfile对其进行配置并安装插件。 最后,您将学习在发布新版本时如何升级安装。

先决条件 (Prerequisites)

第1步-建立球童 (Step 1 — Building Caddy)

In this step, you’ll build Caddy from source with the ability to later add plugins, all without changing Caddy’s source code.

在此步骤中,您将从源代码构建Caddy,并具有以后添加插件的能力,而无需更改Caddy的源代码。

For the purposes of this tutorial, you’ll store the source code under ~/caddy. Create that directory by running the following command:

就本教程而言,您会将源代码存储在~/caddy 。 通过运行以下命令来创建该目录:

  • mkdir ~/caddy

    麦克迪尔〜/ caddy

Navigate to it:

导航到它:

  • cd ~/caddy

    cd〜/球童

You’ll store the source code for running and customizing Caddy in a file named caddy.go. Create it using the following command:

您会将用于运行和自定义Caddy的源代码存储在名为caddy.go的文件中。 使用以下命令创建它:

  • nano caddy.go

    纳米球童

Add the following lines:

添加以下行:

~/caddy/caddy.go
〜/ caddy / caddy.go
package main

import (
    "github.com/caddyserver/caddy/caddy/caddymain"
)

func main() {
    // caddymain.EnableTelemetry = false
    caddymain.Run()
}

This code imports Caddy directly from Github (using Git) and starts it from the entrance main function. If you wish to enable telemetry, uncomment the caddymain.EnableTelemetry line and set the value to true. When you are done, save and close the file.

该代码直接从Github导入Caddy(使用Git),并从入口main函数启动它。 如果要启用遥测,请取消注释caddymain.EnableTelemetry行并将其值设置为true 。 完成后,保存并关闭文件。

For caddy.go to be able to use the imported dependencies, you’ll need to initialize it as a module:

为了使caddy.go能够使用导入的依赖项,您需要将其初始化为模块:

  • go mod init caddy

    去mod初始化球童

   
   
   
Output
go: creating new go.mod: module caddy

At this point, you’re all set to build the stock version of Caddy from the above source code by running:

至此,您都可以通过运行以下代码从上述源代码构建Caddy的普通版:

  • go install

    去安装

There will be a lot of output, detailing what libraries Go downloaded as dependencies necessary for compiling. The resulting executable is stored under $GOPATH/bin, as explained in the prerequisites.

将有很多输出,详细说明了哪些库要下载作为编译所需的依赖项。 如前提条件中所述,生成的可执行文件存储在$GOPATH/bin下。

When it finishes, try running Caddy:

完成后,请尝试运行Caddy:

  • caddy

    球童

You’ll see output similar to the following:

您将看到类似于以下内容的输出:


   
   
   
Output
Activating privacy features... do
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值