Skip to content

Instantly share code, notes, and snippets.

@jniltinho
Last active February 28, 2024 10:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jniltinho/9bd76fd13cf3fc4dd60f1a9eec509492 to your computer and use it in GitHub Desktop.
Save jniltinho/9bd76fd13cf3fc4dd60f1a9eec509492 to your computer and use it in GitHub Desktop.
Install Caddy Web Server on Linux
#!/bin/bash
## Install Caddy 2 Web Server Linux
## https://temelkuran.ist/caddy-server-2-php-fpm-installation-on-ubuntu-server-19-10/
## https://caddy.community/t/fastcgi-using-unix-socket-with-caddy-2/6376
## https://caddy.community/t/v2-subfolder-proxy-to-upstream-root/7095/7
## https://caddyserver.com/
# https://github.com/caddyserver/caddy
wget https://github.com/caddyserver/caddy/releases/download/v2.0.0/caddy_2.0.0_linux_amd64.tar.gz
tar -xvf caddy_2.0.0_linux_amd64.tar.gz
rm -f LICENSE README.md caddy_2.0.0_linux_amd64.tar.gz
mv caddy /usr/bin/
wget https://raw.githubusercontent.com/caddyserver/dist/master/init/caddy.service
sed -i "s|User=caddy|User=www-data|" caddy.service
sed -i "s|Group=caddy|Group=www-data|" caddy.service
mv caddy.service /etc/systemd/system/
mkdir -p /etc/caddy/conf.d/
echo 'import /etc/caddy/conf.d/*.conf' >/etc/caddy/Caddyfile
echo ':80 {
root * /var/www/html
file_server
}' > /etc/caddy/conf.d/webapp.conf
systemctl daemon-reload
systemctl enable caddy
systemctl start caddy
:8585 {
root * /var/www/laravel/app/public
php_fastcgi / unix//var/run/php/php7.2-fpm.sock
try_files {path} {path}/ /index.php?{query}
file_server
}
# caddy.service
#
# For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# See https://caddyserver.com/docs/install for instructions.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.
[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target
[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
:8484 {
root * /var/www/vue/app/public
file_server
try_files {path} /webapp/index.html
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment