83 lines
No EOL
2.4 KiB
Markdown
Executable file
83 lines
No EOL
2.4 KiB
Markdown
Executable file
# 20240205150537 Caddyをraspi4にインストール
|
||
#raspi #caddy #web_server
|
||
|
||
|
||
[How to Setup a Raspberry Pi Caddy Web Server - Pi My Life Up](https://pimylifeup.com/raspberry-pi-caddy-web-server/) の方法が現在 20240205 は利用できない。
|
||
```sh
|
||
Err:4 https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version InRelease
|
||
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY ABA1F9B8875A6661
|
||
```
|
||
このgpgエラーは、鍵が公開されていないのか、解決不能。
|
||
|
||
仕方ないのでソースからビルド。
|
||
|
||
まずgoが必要。
|
||
[[20240205152229 raspi4にgoをインストールする|raspi4にgoをインストールする]]
|
||
|
||
caddyをビルド。
|
||
```sh
|
||
$ sudo apt install git (インストールしてなければ)
|
||
$ git clone --depth=1 https://github.com/caddyserver/caddy.git
|
||
$ cd caddy/cmd/caddy/
|
||
$ go build
|
||
$ cd ../../..
|
||
$ sudo mv caddy /usr/local
|
||
```
|
||
`/usr/local/caddy/cmd/caddy`
|
||
にパスを通す。 /etc/profileに追加。
|
||
|
||
```
|
||
$ sudo setcap cap_net_bind_service=+ep /usr/local/caddy/cmd/caddy/caddy
|
||
$ sudo visudo
|
||
```
|
||
|
||
`username ALL=(ALL:ALL) NOPASSWD: /usr/sbin/setcap` を追加。
|
||
|
||
WEBサーバーのルートを作る
|
||
```
|
||
$ sudo mkdir /var/www
|
||
$ sudo chmod a+rw /var/www
|
||
```
|
||
|
||
Caddyfileを /etc 以下に作成
|
||
```
|
||
$ sudo mkdir /etc/caddy/
|
||
$ sudo toucn /etc/caddy/Caddyfile
|
||
```
|
||
|
||
Caddyfileを編集
|
||
```
|
||
localhost, 127.0.0.1 192.168.1.100(自分で決めたIPアドレス) saipi4.local(自分で決めたhostname) {
|
||
root * /var/www
|
||
file_server
|
||
}
|
||
|
||
```
|
||
/var/wwwにindex.htmlを作成
|
||
|
||
```
|
||
<!doctype html>
|
||
<html>
|
||
<head>
|
||
<title>This is the title of the webpage!</title>
|
||
</head>
|
||
<body>
|
||
<p>All your base are belong to us.</p>
|
||
</body>
|
||
</html>
|
||
```
|
||
|
||
caddyを起動
|
||
```
|
||
caddy run --config /etc/caddy/Caddyfile
|
||
```
|
||
色々怒られるかもだけど、とりあえずネットワーク内から接続できる。
|
||
|
||
![[Pasted image 20240205205804.png]]
|
||
|
||
cf.
|
||
[GitHub - caddyserver/caddy: Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS](https://github.com/caddyserver/caddy?tab=readme-ov-file#build-from-source)
|
||
|
||
[caddyで簡単にhttpsサイト #http2 - Qiita](https://qiita.com/mmotoi/items/1af28e2e62a4e344eb6c)
|
||
|
||
[Caddy:Caddyfileに\`localhost\`を指定すると、https://127.0.0.1/ ではアクセスできない](https://zenn.dev/yuji38kwmt/articles/5d3e729dc9a5c1) |