Centos8 安装 Caddy Web服务器,你会了吗?
系统运维 2025-10-09 02:44:55
0
Caddy Web 服务器是安装一个开源的、支持 HTTP/2 的服务 Web 服务器,使用 Go 语言编写。安装Caddy 最显着的服务功能之一是云服务器提供商自动为托管网站启用 TLS。Caddy 自动从 Lets Encrypt 获取和更新 TLS 证书。安装Caddy 也可以配置为反向代理服务器。服务
在本文中,安装将在 CentOS 8 中安装 Caddy Web 服务器并在 Caddy 上配置 HTTP网站。服务
Caddy有一下功能:
支持 HTTP/1.1 和 HTTP/2自动配置HTTPS支持虚拟主机IPv4和IPv6反向代理带健康检查的安装负载平衡GZip压缩环境信息
系统:Centos8主机名:caddy.example.comIP地址:192.168.43.131
安装Caddy Web服务器
使用下面命令安装caddy:
复制[root@caddy ~]# yum -y install dnf-command(copr)[root@caddy ~]# yum copr enable @caddy/caddy
[root@caddy ~]# yum -y install caddy1.2.3.找到 Caddy Web 服务器的云服务器安装目录:
复制[root@caddy ~]# whereis caddy
caddy: /usr/bin/caddy /etc/caddy /usr/share/caddy1.2.为 Caddy Web 服务器创建目录结构
下面为Caddy服务创建存放证书的目录:
复制[root@caddy ~]# mkdir /etc/ssl/caddy
[root@caddy ~]# chown -R caddy:root /etc/ssl/caddy/[root@caddy ~]# chmod o-rwx /etc/ssl/caddy/1.2.3.启用caddy服务
复制[root@caddy ~]# systemctl enable caddy
Created symlink /etc/systemd/system/multi-user.target.wants/caddy.service → /usr/lib/systemd/system/caddy.service.
[root@caddy ~]# systemctl start caddy1.2.3.在浏览器输入服务器ip地址,可访问默Caddy的服务默认页面。
在 Caddyfile 中创建一个服务器配置
在Caddyfile文件中创建一个简单的安装服务器配置:
复制[root@caddy ~]# vim /etc/caddy/Caddyfile
:80 { # Set this path to your sites directory.root * /var/www/html# Enable the static file server.file_servergzip# Another common task is to set up a reverse proxy:# reverse_proxy localhost:8080# Or serve a PHP site through php-fpm:# php_fastcgi localhost:9000}[root@caddy html]# echo "<h1>Hello World</h1>" > /var/www/html/index.html1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.重启一下caddy服务:
复制[root@localhost ~]# systemctl restart caddy1.访问测试一下:
防火墙开启http:
复制[root@localhost ~]# firewall-cmd --permanent --add-service=httpsuccess
[root@localhost ~]# firewall-cmd --reloadsuccess1.2.3.4.总 结
如我们已经在 CentOS 8 上成功安装了 Caddy Web 服务器,并使用 Caddy 发布了 HTTP 网站。服务器托管服务
安装