CentOS 8.5にcaddy2.4.6をインストールする

2021年12月21日

環境
OSバージョンの確認
# cat /etc/redhat-release
CentOS Linux release 8.5.2111

caddyのインストールの方法
1.caddy2.0をインストールします

# sudo dnf install 'dnf-command(copr)'
# sudo dnf copr enable @caddy/caddy
Enabling a Copr repository. Please note that this repository is not part
of the main distribution, and quality may vary.

The Fedora Project does not exercise any power over the contents of
this repository beyond the rules outlined in the Copr FAQ at
<https://docs.pagure.org/copr.copr/user_documentation.html#what-i-can-build-in-copr>,
and packages are not held to any quality or security level.

Please do not file bug reports about these packages in Fedora
Bugzilla. In case of problems, contact the owner of this repository.

Do you really want to enable copr.fedorainfracloud.org/@caddy/caddy? [y/N]: y #yを入力
Repository successfully enabled.

caddyをインストールします

# sudo dnf install caddy
略
Installed:
  caddy-2.4.6-1.el8.x86_64

バージョンを確認します

# caddy version
v2.4.6 h1:HGkGICFGvyrodcqOOclHKfvJC0qTU7vny/7FhYp9hNw=

2.caddyを起動します
# sudo systemctl start caddy

ステータスを確認します

# sudo systemctl status caddy
● caddy.service - Caddy
   Loaded: loaded (/usr/lib/systemd/system/caddy.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2021-12-20 23:53:38 PST; 5s ago

3.Firewallを設定します

ポート番号80を許可します
# sudo firewall-cmd --add-port=80/tcp --zone=public --permanent
success
# sudo firewall-cmd --reload
success 

4.動作確認
ブラウザからhttp://IPアドレス(ホスト名)にアクセスします

5.ドキュメントルートを確認します

# cat /etc/caddy/Caddyfile
# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.

:80 {
        # Set this path to your site's directory.
        root * /usr/share/caddy

        # Enable the static file server.
        file_server

        # 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
}

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

6.テストプログラムを作成します
# cd /usr/share/caddy
# vi sample.html
this is a caddy test page
動作確認
http://IPアドレス(ホスト名)にsample.html

 

CentOS8

Posted by arkgame