Lewati ke konten
Client Panel

Configuration Caddy

Konten ini belum tersedia dalam bahasa Anda.

Artikel ini belum diterjemahkan. Isi berikut berbahasa Inggris. Buka versi asli bahasa Inggris.

Sample Configuration for Caddy as Web server. You can choose one that fit your condition.

Configuration for Caddy as a Reverse Proxy.

Reverse Proxy for pointing the Web Server to Web Application Server IP and Bind the domain.

/etc/caddy/Caddyfile
ksara.xyz {
reverse_proxy http://localhost:3000
}

The Advanced configuration to add X-Forwarded, Log Output and other else.

/etc/caddy/Caddyfile
ksara.xyz {
reverse_proxy http://localhost:3000 {
header_up X-Forwarded-Proto https
header_up X-Url-Scheme {scheme}
header_up X-Real-IP {remote}
}
file_server
encode gzip zstd
log {
output file /var/log/caddy/access-ksara.xyz.log
format json
}
@static {
file path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.pdf *.webp
}
header @static Cache-Control max-age=5184000
}

Advanced Config for Reverse Proxy - Wildcard with Cloudflare Proxy

Section titled “Advanced Config for Reverse Proxy - Wildcard with Cloudflare Proxy”

The Advanced configuration to add X-Forwarded, Log Output and other else with Cloudflare Proxy full-strict. You can put your Cloudflare certificate (CA). You can create the CA on Your Domain > SSL/TLS > Origin Server. Also, X-Forwareded-For from Real IP that request to Cloudflare.

/etc/caddy/Caddyfile
*.ksara.xyz {
tls /etc/ssl/certs/cf-cert.pem /etc/ssl/certs/cf-priv.key
reverse_proxy https://localhost:3000 {
transport http {
tls
tls_insecure_skip_verify
}
header_up X-Forwarded-Proto https
header_up X-Url-Scheme {scheme}
header_up X-Real-IP {remote}
header_up X-Forwarded-For {http.request.header.CF-Connecting-IP}
}
encode gzip zstd
file_server
log {
output file /var/log/caddy/service-compute-ksara.log
}
}

Configuration for Caddy as a Virtual Host.

Web Server to Static Web Directory.

/etc/caddy/Caddyfile
ksara.xyz {
root * /var/www/html/ksara.xyz
file_server
encode gzip zstd
@static {
file path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.pdf *.webp
}
header @static Cache-Control max-age=5184000
}

Web Server to PHP Web Directory.

Install additional module to execute PHP.

Terminal window
sudo dnf install php-fpm php-cli php-gd -y

Configuration File Sample.

/etc/caddy/Caddyfile
ksara.xyz {
root * /var/www/html/ksara.xyz
file_server
encode gzip zstd
php_fastcgi unix//run/php-fpm/www.sock
}

Edit PHP-FPM Config File and edit some line.

/etc/php-fpm.d/www.conf
user = caddy
group = caddy
listen.acl_users = apache,nginx,caddy

Restart PHP-FPM Services.

Terminal window
systemctl start php-fpm
systemctl enable --now php-fpm

Configuration for Caddy as a File Server.

Web Server to serve file. Also, implement the basic auth to login before access the file directory. You can generate with bcrypt.

/etc/caddy/Caddyfile
fileserver.ksara.xyz {
basicauth * {
user1 $2a$12$3gR4jgPU1fVmJ6/Um3aPpeJXBx5I2xEl3pCHYpa9umxZzDgvFMtBu
}
encode gzip zstd
root * /var/www/file
file_server browse
log {
output file /var/log/caddy/file-ksara.log
}
}

To Validate and Format Caddy configuration.

Terminal window
caddy validate --adapter caddyfile --config /etc/caddy/Caddyfile
caddy fmt --overwrite /etc/caddy/Caddyfile

Restart the Caddy Service.

Terminal window
sudo systemctl restart caddy