GNU/Linux >> Linux Esercitazione >  >> Cent OS

Come installare Caddy Web Server su CentOS 7

In questo tutorial, ti mostreremo come installare il server Web Caddy su CentOS 7. Per quelli di voi che non lo sapessero, il server Web Caddy è open-source e server Web incentrato sulla sicurezza scritto in Go. Caddy include funzionalità moderne come supporto per host virtuali, minimizzazione di file statici e HTTP/2.

Questo articolo presuppone che tu abbia almeno una conoscenza di base di Linux, sappia come usare la shell e, soprattutto, che ospiti il ​​tuo sito sul tuo VPS. L'installazione è abbastanza semplice e presuppone che tu sono in esecuzione nell'account root, in caso contrario potrebbe essere necessario aggiungere 'sudo ' ai comandi per ottenere i privilegi di root. Ti mostrerò l'installazione passo passo del Caddy Web Server su un server CentOS 7.

Prerequisiti

  • Un server che esegue uno dei seguenti sistemi operativi:CentOS 7.
  • Si consiglia di utilizzare una nuova installazione del sistema operativo per prevenire potenziali problemi.
  • Accesso SSH al server (o semplicemente apri Terminal se sei su un desktop).
  • Un non-root sudo user o accedere all'root user . Ti consigliamo di agire come non-root sudo user , tuttavia, poiché puoi danneggiare il tuo sistema se non stai attento quando agisci come root.

Caratteristiche del carrello

  • HTTPS automatico.
  • Facile implementazione.
  • Multicore.
  • WebSocket.
  • Riscritture e reindirizzamenti.
  • Host virtuali.

Installa Caddy Web Server su CentOS 7

Passaggio 1. Innanzitutto, iniziamo assicurandoci che il tuo sistema sia aggiornato.

yum clean all
yum -y update

Passaggio 2. Installazione del server web Caddy su CentOS 7.

Installare Caddy è facile e veloce con il seguente comando:

curl https://getcaddy.com | bash

Al termine dello script, puoi eseguire il seguente comando per vedere dove si trova il file binario di Caddy:

which caddy

Il tuo output dovrebbe essere come il seguente:

/usr/local/bin/caddy

Passaggio 3. Impostazione delle directory necessarie.

Successivamente, crea le directory in cui memorizzeremo il file di configurazione Caddy Caddyfile e i certificati SSL:

mkdir /etc/caddy
chown -R root:caddy /etc/caddy
touch /etc/caddy/Caddyfile
mkdir /etc/ssl/caddy
chown -R caddy:root /etc/ssl/caddy
chmod 0770 /etc/ssl/caddy
mkdir /var/www
chown caddy:caddy /var/www

Passaggio 4. Installazione di Caddy come servizio di sistema.

Dobbiamo anche creare un nuovo script di configurazione di SystemD:

cd /etc/systemd/system/
nano caddy.service

Aggiungi la seguente riga:

[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
Restart=on-failure
StartLimitInterval=86400
StartLimitBurst=5

; User and group the process will run as.
User=caddy
Group=caddy

; Letsencrypt-issued certificates will be written to this directory.
Environment=CADDYPATH=/etc/ssl/caddy

; Always set "-root" to something safe in case it gets forgotten in the Caddyfile.
ExecStart=/usr/local/bin/caddy -log stdout -agree=true -conf=/etc/caddy/Caddyfile -root=/var/tmp
ExecReload=/bin/kill -USR1 $MAINPID

; Limit the number of file descriptors; see `man systemd.exec` for more limit settings.
LimitNOFILE=1048576
; Unmodified caddy is not expected to use more than that.
LimitNPROC=64

; Use private /tmp and /var/tmp, which are discarded after caddy stops.
PrivateTmp=true
; Use a minimal /dev
PrivateDevices=true
; Hide /home, /root, and /run/user. Nobody will steal your SSH-keys.
ProtectHome=true
; Make /usr, /boot, /etc and possibly some more folders read-only.
ProtectSystem=full
; … except /etc/ssl/caddy, because we want Letsencrypt-certificates there.
;   This merely retains r/w access rights, it does not add any new. Must still be writable on the host!
ReadWriteDirectories=/etc/ssl/caddy

; The following additional security directives only work with systemd v229 or later.
; They further retrict privileges that can be gained by caddy. Uncomment if you like.
; Note that you may have to add capabilities required by any plugins in use.
;CapabilityBoundingSet=CAP_NET_BIND_SERVICE
;AmbientCapabilities=CAP_NET_BIND_SERVICE
;NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

Imposta il proprietario e le autorizzazioni:

chown root:root /etc/systemd/system/caddy.service
chmod 644 /etc/systemd/system/caddy.service

Alla fine, esegui i seguenti comandi per consentire a Caddy di essere eseguito all'avvio:

systemctl enable caddy
systemctl start caddy

Passaggio 5. Creazione di una pagina Web di prova e di un Caddyfile.

A scopo di test, creeremo un file HTML di prova:

mkdir -p /var/www/my-domain.com
echo "Caddy" > /var/www/idroot.us/index.html
chown -R www-data: /var/www/my-domain.com

In seguito, aggiungi il nostro dominio al file di configurazione di Caddy:

nano /etc/caddy/Caddyfile

Aggiungi la seguente riga:

my-domain.com {
    root /var/www/idroot.us
}

Salva il file ed esci dall'editor. Per applicare le modifiche, riavvia Caddy:

systemctl restart caddy.service

Ora, con un browser web, vai su https://my-domain.com e vedrai la nostra pagina di prova!

Congratulazioni! Hai installato correttamente Caddy. Grazie per aver utilizzato questo tutorial per l'installazione del server Web Caddy nel sistema CentOS 7. Per ulteriore aiuto o informazioni utili, ti consigliamo di controllare il Web Caddy ufficiale sito web del server.


Cent OS
  1. Come installare Apache Web Server su CentOS 7

  2. Come installare il server Minecraft su CentOS 7

  3. Come installare Nginx su CentOS 8

  4. Come installare Teamspeak 3 Server su CentOS 8

  5. Come installare Apache Web Server su Centos 8

Come installare il server Web Apache su CentOS 8

Come installare il server Web Lighttpd su CentOS 8

Come installare il server Web Cherokee su CentOS 6

Come installare Jetty Web Server su CentOS 7

Come installare Hiawatha Web Server su CentOS 7

Come installare Caddy Web Server su CentOS 8