# caddy.service 라는 이름의 파일을 만든다 (주소는 아래와 같이)
sudo vi /etc/systemd/system/caddy.service
# 그리고 아래를 복붙한다
[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target
[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
Caddyfile에 내용을 입력해준다
sudo vi /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
# 이렇게 수정을 해 놓으면 된다
<EC2 인스턴스의 퍼블릭 IPv4 주소>.nip.io {
reverse_proxy localhost:8080 # 들어오는 요청을 8080포트로 포워딩
}
Caddy 실행하기
sudo systemctl daemon-reload
sudo systemctl enable --now caddy
# Caddy가 잘 작동이 되었는지 확인 하는 것이다
# 확인을 할 때에 Active 부분에서 active면 작동이 잘 되고 있는 것이다
systemctl status -l caddy
에러가 떠서, Caddyfile을 수정 할 때마다, 위 명령어를 실행했다
원래 sudo caddy start를 하면, Caddy가 실행되지만, sudo systemctl enable --now caddy 이 부분에서 실행이 될 수 있다
그렇게 되면 아래와 같이 에러 메세지가 뜨게 된다
처음에는 프로세스를 죽이고 다시 시작했지만, 나중에는 Caddy가 작동이 잘 되는 것을 보고, 그냥 어플리케이션을 실행 했더니 잘 되었다
# 실행 명령어!
sudo caddy start
Error: loading initial config: loading new config: starting caddy administration endpoint: listen tcp 127.0.0.1:2019: bind: address already in use
해당 에러라 계속 뜬다;;;
그래서 해당 프로세서를 찾아서, 중단을 시킨 뒤 다시 실행을 했다
이미 실행중인 127.0.0.1:2019 이 있어서 그렇다
# 프로세스 찾기 (여기서 PID를 찾으면 된다)
sudo lsof -i :2019
# 프로세스 죽이기
sudo kill -9 {PID}