徒然
つれづれなるままに、日暮らし

Ubuntu22.04にCaddyをインストール

UbuntuCaddy
制作日: 2024年03月12日
更新日: 2024年03月22日
Caddyをインストール

Ubuntu22.04とCaddyでwebサイトを動かすまでのメモ

Ubuntu

更新

sudo apt update
sudo apt upgrade
sudo apt autoremove

アップグレードマネージャのインストール

sudo apt install -y update-manager-core

アップグレードの実行

sudo do-release-upgrade -d

バージョン確認

cat /etc/os-release

ユーザーの作成

useradd -mG sudo {username}
passwd {passwd}
touch /home/{username}/.ssh/authorized_keys
chmod 700 .ssh
chmod 600 authorized_keys

作成したユーザにsshキーを渡す

cat ~/.ssh/{keyname}.pub | ssh {username}@{keyname} 'cat >> /home/{username}/.ssh/authorized_keys'

sshのポート番号を変更

vim /etc/ssh/sshd_config
- #Port 22
+ Port {Port番号}

再起動

systemctl restart sshd

firewalldコマンドインストール

sudo apt-get -y install firewalld

firewalldサービスを起動

systemctl start firewalld
systemctl status firewalld

使えるサービス一覧にsshがあるか確認

firewall-cmd --get-services | grep ssh

sshのxmlファイルをコピーしてポート22を{Port番号}に書き換える

これを実行する際はサーバー側も同一ポートを開けること

cp /usr/lib/firewalld/services/ssh.xml /etc/firewalld/services/ssh.xml
sed -i 's/22/{Port番号}/g' /etc/firewalld/services/ssh.xml
firewall-cmd --reload

sshd configの設定

etc/ssh/sshd_config
- #Protocol 2
+ Protocol 2

- #RSAAuthentication no
+ RSAAuthentication no

- #PermitEmptyPasswords no
+ PermitEmptyPasswords no

- #ChallengeResponseAuthentication no
+ ChallengeResponseAuthentication no

- #KerberosAuthentication no
+ KerberosAuthentication no

- #GSSAPIAuthentication no
+ GSSAPIAuthentication no

- #X11Forwarding no
+ X11Forwarding no

+ AllowUsers {username}

再起動

systemctl restart sshd

gitを最新に

sudo apt remove git
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git
git --version

Caddy

オープンソースのHTTP/2、HTTP/3に対応したWebサーバ。
Go 言語で記述されており、HTTP機能にはGo標準ライブラリが使用されている。
自動的にhttpsが有効になる特徴がある。

インストール

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy

自動起動

sudo systemctl enable caddy

ファイアウォールを設定

sudo ufw allow proto tcp from any to any port 80,443

caddy fileの設定

/etc/caddy/caddyfile
tozen.me {
    reverse_proxy localhost:3000
}

www.tozen.me {
    redir https://tozen.me{uri}
}

再起動

systemctl restart caddy
  • このサイトについて
  • プライバシーポリシー
Copyright© 徒然. All Rights Reserved.
徒然