ืขืก ืืื ืึท ืคึผืืึทืฅ ืคืื ืืึทืืขืจืืึทื ืืืืฃ ืื ืกืืึธืืื ื ืืืึธืจืืคึผืจืขืกืก; ืึท Google ืืืื ืคึฟืึทืจ "ืืืึธืจืืคึผืจืขืกืก ืื ืกืืึทืืืจื" ืืืขื ืฆืืจืืงืงืืืขื ืืืขืื ืึท ืืึทืื ืืืืืึธื ืจืขืืืืืึทืื. ืึธืืขืจ, ืขืก ืืขื ืขื ืคืืงืืืฉ ืืืืขืจ ืืืืื ืืง ื ืืฆืืง ืืืืืขืก ืืืึธืก ืงืขื ืขื ืืขืืคึฟื ืืืจ ืื ืกืืึทืืืจื ืืื ืงืึทื ืคืืืืขืจ ืืืึธืจืืคึผืจืขืกืก ืืื ืื ืึทื ืืขืจืืืืื ื ืึธืคึผืขืจืืืืื ื ืกืืกืืขื ืึทืืื ืึทื ืืื ืงืขื ืขื ืืืื ืืขืฉืืืฆื ืืืืขืจ ืึท ืืึทื ื ืฆืืื. ืืึธืืขืจ ืื ืจืืืืืง ืกืขืืืื ืืก ืึธืคืขื ืืขื ืฉืืืขืจ ืืืืฃ ืืืื ืกืคึผืขืฆืืคืืฉ ืืืืขืจืคืขื ืืฉื, ืึธืืขืจ ืขืก ืงืขื ืืืื ืืืืึทื ืื ืืืืืืื ืืขืจืงืืขืจืื ื ืืืื ืืขื ืึทืจืืืงื ืฉืืืขืจ ืฆื ืืืืขื ืขื.
ืืื ืืขื ืึทืจืืืงื, ืืืจ ืืืขืื ืคึผืจืืืืจื ืฆื ืฉืืขืื ืฆืืืึทืืขื ืื ืืขืกืืขืจ ืคืื ืืืืืข ืืืขืืื ืืืจื ืฆืืฉืืขืื ืึท ืืึทืฉ ืฉืจืืคื ืฆื ืืืืืึธืืึทืืืฉ ืื ืกืืึทืืืจื ืืืึธืจืืคึผืจืขืกืก ืืืืฃ ืืืื ืื, ืืื ืืืจ ืืืขืื ืืืจืืืืื ืขืก, ืืขืจืงืืขืจื ืืืึธืก ืืขืืขืจ ืฉืืืง ืืื ืืื ืื ืืึทื ืื-ืึธืคืก ืืืึธืก ืืืจ ืืึธืื ืืขืืืื ืืื ืืืืืื ืื ื. ืขืก. ืืืื ืืืจ ืืขื ื ืึท ืืงืกืคึผืืจืืึทื ืกื ืืึทื ืืฆืขืจ, ืืืจ ืงืขื ืขื ืืึธืคึผืงืขื ืืขื ืืขืงืกื ืคืื ืืขื ืึทืจืืืงื ืืื ื ืึธืจ
ืื ืืขืืืขืืึธืคึผืขื ืึทืจืงืึทืืขืงืืฉืขืจ ืคึฟืึทืจ ืืืคึผืืืืื ื ืืืึธืจืืคึผืจืขืกืก ื ืืฆื NGINX Unit ืืื ืืืกืงืจืืืื ืืื
- ืืืึธืจืืคึผืจืขืกืก CLI
- ืืึธืืืจ ืขื ืงืจืืคึผื ืืื TLSSSL ืกืขืจืืืคืืงืึทืฅ
- ืึธืืึทืืึทืืืง ืืึทืืืืึทืื ืจืื ืืึทื
- NGINX ืงืึทืืฉืื ื
- NGINX ืงืึทืืคึผืจืขืฉืึทื
- ืืืืคึผืก ืืื ืืืืคึผ / 2 ืฉืืืฆื
- ืคึผืจืึธืฆืขืก ืึธืืึทืืืืฉืึทื
ืืขืจ ืึทืจืืืงื ืืืขื ืืึทืฉืจืืึทืื ืื ืกืืึทืืืจืื ื ืืืืฃ ืืืื ืกืขืจืืืขืจ, ืืืึธืก ืืืขื ืกืืืืึทืืืืื ืืึทืกืื ืืึทืืขืืึธืก ืึท ืกืืึทืืืง ืคึผืจืึทืกืขืกืื ื ืกืขืจืืืขืจ, ืึท PHP ืคึผืจืึทืกืขืกืื ื ืกืขืจืืืขืจ ืืื ืึท ืืึทืืึทืืืืก. ืืึทื ืืึธื ืืืจืื ื ืืื ืฉืืืฆื ืคึฟืึทืจ ืงืืืคื ืืืืจืืืึทื ืืื ืืช ืืื ืืึทืืื ืื ืืก ืืื ืึท ืคึผืึธืืขื ืฆืืขื ืืขืืข ืคึฟืึทืจ ืืขืจ ืฆืืงืื ืคึฟื. ืืืื ืืืจ ืืืืื ืึทื ืืืจ ืฉืจืืึทืื ืืืขืื ืขืคึผืขืก ืืืึธืก ืืื ื ืืฉื ืืื ืื ืึทืจืืืงืืขื, ืฉืจืืึทืื ืืื ืื ืืึทืืขืจืงืื ืืขื.
ืืืืขืจืคืขื ืืฉื
- ืกืขืจืืืืจืขืจ ืงืึทื ืืืื ืขืจ (
ืืงืกืง ืึธืืขืจืืงืกื ), ืึท ืืืืจืืืึทื ืืึทืฉืื, ืึธืืขืจ ืึท ืจืขืืืืขืจ ืืึทืื ืืืึทืจื ืกืขืจืืืขืจ, ืืื ืืคึผืืืช 512 ืื ืคืื ืืึทืจืึทื ืืื Ubuntu 18.04 ืึธืืขืจ ืืขืจ ืืขืฆืื ืก ืืื ืกืืึทืืืจื. - ืืื ืืขืจื ืขื ืฆืืืจืื ืคึผืึธืจืฅ 80 ืืื 443
- ืื ืคืขืื ื ืึธืืขื ืคึฟืึทืจืืื ืื ืืื ืื ืขืคื ืืืขื IP ืึทืืจืขืก ืคืื ืืขื ืกืขืจืืืขืจ
- ืึทืงืกืขืก ืืื ืืืึธืจืฆื ืจืขืื (ืกืืืึธ).
ืึทืจืงืึทืืขืงืืฉืขืจ ืืืืขืจืืืืง
ืื ืึทืจืงืึทืืขืงืืฉืขืจ ืืื ืื ืืขืืืข ืืื ืืืกืงืจืืืื
ืึทืืืขืืืื ืข ืคึผืจืื ืฆืืคึผื
- ืคืืืข ืงืึทื ืคืืืืขืจืืืฉืึทื ืงืึทืืึทื ืื ืืื ืึท ืฉืจืืคื ืืขื ืขื ืืื ืืขืืืืงืื ืืื ืืืื ืื ืึธืื ืคึฟืึทืจ ืืืขืืึธืืขื ืกื: ืื ืฉืจืืคื ืงืขื ืขื ืืืื ืืืืคื ืขืืืขืืข ืืึธื ืึธื ืื ืจืืืืงืืจื ืคืื ืืฉืึทื ืืื ื ืกืขืืืื ืืก ืืืึธืก ืืขื ืขื ืฉืืื ืืจืืื.
- ืืขืจ ืฉืจืืคื ืคืจืืืื ืฆื ืื ืกืืึทืืืจื ืืืืืืืืืจื ืคึฟืื ืจืืคึผืึทืืึทืืึธืจืื, ืึทืืื ืืืจ ืงืขื ืขื ืฆืืืืืื ืกืืกืืขื ืืขืจืืืึทื ืืืงืื ืืขื ืืื ืืืื ืืึทืคึฟืขื (
apt upgrade
ืคึฟืึทืจ ืืืื ืื). - ืืืื ืคึผืจืืืืจื ืฆื ืืขืืขืงื ืึทื ืืื ืืืืคื ืืื ืึท ืงืึทื ืืืื ืขืจ ืึทืืื ืืื ืงืขื ืขื ืืืืฉื ืืืืขืจ ืกืขืืืื ืืก ืึทืงืึธืจืืื ืืื.
- ืืื ืกืืจ ืฆื ืฉืืขืื ืื ื ืืืขืจ ืคืื ืคืึธืืขื ืคึผืจืึทืกืขืกืึทื ืฆื ืืืื ืืึธื ืืฉื ืืื ืื ืกืขืืืื ืืก, ืื ืฉืจืืคื ืคืจืืืื ืฆื ืืจืขืคื ืื ืึธืืึทืืึทืืืง ืกืขืืืื ืืก ืคึฟืึทืจ ืืจืืขืื ืืื ืงืึทื ืืืื ืขืจื, ืืืืจืืืึทื ืืืฉืื ืขื ืืื ืืึทืื ืืืึทืจื ืกืขืจืืืขืจืก.
- ืืืขื ืืืกืงืจืืืืื ื ืกืขืืืื ืืก, ืืืจ ืฉืืขื ืืืง ืืจืึทืืื ืขืจืฉืืขืจ ืืืขืื ืึธืืึทืืืืฉืึทื, ืืืึธืก ืืืจ ืืึธืคึฟื ืืืขื ืืืขืจื ืื ืืงืขืจ ืคึฟืึทืจ ืงืจืืืืืื ื ืืืื ืืืืืขื ืข ืื ืคืจืึทืกืืจืึทืงืืฉืขืจ ืืื ืงืึธื.
- ืื ืงืึทืืึทื ืื ืืขื ืขื ืืืืคื ืคืื ืื ืืึทื ืืฆืขืจ ืืืึธืจืฆื, ืืืืึทื ืืื ืืืืฉื ืื ืืงืขืจืืืง ืกืืกืืขื ืกืขืืืื ืืก, ืึธืืขืจ ืืืึธืจืืคึผืจืขืกืก ืืื ืืืืคื ืืื ืึท ืจืขืืืืขืจ ืืึทื ืืฆืขืจ.
ืืึทืฉืืขืืืงื ืกืืืืืืข ืืืขืจืืึทืืึทืื
ืฉืืขืื ืื ืคืืืืขื ืืข ืกืืืืืืข ืืืขืจืืึทืืึทืื ืืืืืขืจ ืคืืืกื ืืืง ืื ืฉืจืืคื:
WORDPRESS_DB_PASSWORD
- ืืืึธืจืืคึผืจืขืกืก ืืึทืืึทืืืืก ืคึผืึทืจืึธืWORDPRESS_ADMIN_USER
- ืืืึธืจืืคึผืจืขืกืก ืึทืืืื ื ืืืขืWORDPRESS_ADMIN_PASSWORD
- ืืืึธืจืืคึผืจืขืกืก ืึทืืืื ืคึผืึทืจืึธืWORDPRESS_ADMIN_EMAIL
- ืืืึธืจืืคึผืจืขืกืก ืึทืืืื ืืืืฆืคึผืึธืกืWORDPRESS_URL
- ืคืื URL ืคืื ืื ืืืึธืจืืคึผืจืขืกืก ืคึผืืึทืฅ, ืกืืึทืจืืื ื ืืืhttps://
.LETS_ENCRYPT_STAGING
- ืืืืืืง ืืืจื ืคืขืืืงืืึทื, ืึธืืขืจ ืืืจื ืืึทืฉืืขืืืงื ืื ืืืขืจื ืฆื 1, ืืืจ ืืืขื ื ืืฆื Let's Encrypt ืก ืกืืึทืืื ื ืกืขืจืืืขืจืก, ืืืึธืก ืืขื ืขื ื ืืืืืง ืฆื ืึธืคื ืืขืื ืกืขืจืืืคืืงืึทืฅ ืืืขื ืืขืกืืื ื ืืืื ืกืขืืืื ืืก, ืึทื ืืขืจืฉ Let's Encrypt ืงืขื ืืขืืคึผืขืจืขืจืึทืื ืคืึทืจืฉืคึผืึทืจื ืืืื IP ืึทืืจืขืก ืจืขืื ืฆื ืืขืจ ืืจืืืก ื ืืืขืจ ืคืื ืจืืงืืืขืก.
ืืขืจ ืฉืจืืคื ืืฉืขืงืก ืึทื ืื ืืืึธืจืืคึผืจืขืกืก ืคึฟืึทืจืืื ืืขื ืข ืืืขืจืืึทืืึทืื ืืขื ืขื ืืึทืฉืืืื ืืื ืขืืืืฅ ืืืื ืืื ืืขื ืขื ื ืืฉื.
ืฉืจืืคื ืฉืืจืืช 572-576 ืงืึธื ืืจืึธืืืจื ืื ืืืขืจื LETS_ENCRYPT_STAGING
.
ืืึทืฉืืขืืืงื ืืขืจืืืืื ืกืืืืืืข ืืืขืจืืึทืืึทืื
ืื ืฉืจืืคื ืืืืฃ ืฉืืจืืช 55-61 ืฉืืขืื ืื ืคืืืืขื ืืข ืื ืืืืืจืึทื ืืขื ืึทื ืืืขืจืืึทืืึทืื, ืึธืืขืจ ืฆื ืขืืืขืืข ืฉืืืขืจ-ืงืึธืืขื ืืืขืจื ืึธืืขืจ ื ืืฆื ืึท ืืืขืจื ืืขืจืืืืื ืคืื ืื ืืืขืจืืึทืืึทืื ืฉืืขืื ืืื ืื ืคืจืืขืจืืืงืข ืึธืคึผืืืืืื ื:
DEBIAN_FRONTEND="noninteractive"
- ืืขืจืฆืืืื ืึทืคึผืืึทืงืืืฉืึทื ื ืึทื ืืื ืืืืคื ืืื ืึท ืฉืจืืคื ืืื ืขืก ืืื ืงืืื ืืขืืืขืืงืืื ืคืื ืืึทื ืืฆืขืจ ืื ืืขืจืึทืงืฉืึทื.WORDPRESS_CLI_VERSION="2.4.0"
- WordPress CLI ืืืขืจืกืืข ืคืื โโโโืื ืึทืคึผืืึทืงืืืฉืึทื.WORDPRESS_CLI_MD5= "dedd5a662b80cda66e9e25d44c23b25c"
- ืืฉืขืงืกืื ืคืื ืื ืืืึธืจืืคึผืจืขืกืก CLI 2.4.0 ืขืงืกืขืงืืืึทืืืข ืืขืงืข (ืื ืืืขืจืกืืข ืืื ืื ืืขืืืืื ืืื ืื ืืืึทืืขืืืืืงWORDPRESS_CLI_VERSION
). ืื ืฉืจืืคื ืืืืฃ ืฉืืจื 162 ื ืืฆื ืืขื ืืืขืจื ืฆื ืืึทืฉืืขืืืงื ืึทื ืื ืจืืืืืง WordPress CLI ืืขืงืข ืืื ืืึทืื ืืึธืืืื.UPLOAD_MAX_FILESIZE="16M"
- ืื ืืึทืงืกืืืื ืืขืงืข ืืจืืืก ืืืึธืก ืงืขื ืขื ืืืื ืืคึผืืึธืึทืืขื ืฆื ืืืึธืจืืคึผืจืขืกืก. ืื ืืึทืฉืืขืืืงื ืืื ืืขื ืืฆื ืืื ืขืืืขืืข ืขืจืืขืจ, ืึทืืื ืขืก ืืื ืืจืื ืืขืจ ืฆื ืฉืืขืื ืขืก ืืืืฃ ืืืื ืึธืจื.TLS_HOSTNAME= "$(echo ${WORDPRESS_URL} | cut -d'/' -f3)"
- ืกืืกืืขื ืืึธืกืื ืึทืืข, ืืงืกืืจืึทืงืืื ืคืื ืื WORDPRESS_URL ืืืึทืืขืืืืืง. ืืขืืืืื ื ืฆื ืงืจืืื ืฆืื ืขืืขื TLS / SSL ืกืขืจืืืคืืงืึทืฅ ืคืื Let's Encrypt, ืืื ืืขืืื ื ืืื ืคึฟืึทืจ ืื ืขืจืืขื ืืืึธืจืืคึผืจืขืกืก ืืืขืจืึทืคืึทืงืืืฉืึทื.NGINX_CONF_DIR="/etc/nginx"
- ืืจื ืฆื ืืขืจ ืืืขืืืืืึทืืขืจ ืืื NGINX ืกืขืืืื ืืก, ืึทืจืืึทื ืืขืจืขืื ื ืื ืืืืคึผื ืืขืงืขnginx.conf
.CERT_DIR="/etc/letsencrypt/live/${TLS_HOSTNAME}"
- ืืจื ืฆื ืืึธืื ืก ืขื ืงืจืืคึผื ืกืขืจืืืคืืงืึทืฅ ืคึฟืึทืจ ืื ืืืึธืจืืคึผืจืขืกืก ืคึผืืึทืฅ, ืืืงืืืขื ืคึฟืื ืื ืืืึทืืขืืืืืงTLS_HOSTNAME
.
ืึทืกืืื ืื ื ืืึธืกืื ืึทืืข ืฆื ืืืึธืจืืคึผืจืขืกืก ืกืขืจืืืขืจ
ืืขืจ ืฉืจืืคื ืืึทืฉืืขืืืงื ืื ืืึธืกืื ืึทืืข ืคืื โโืื ืกืขืจืืืขืจ ืึทืืื ืึทื ืื ืืืขืจื ืืืืึทืื ืื ืคืขืื ื ืึธืืขื ืคืื ืื ืคึผืืึทืฅ. ืืึธืก ืืื ื ืื ื ืืืืืง, ืึธืืขืจ ืขืก ืืื ืืขืจ ืืึทืงืืืขื ืฆื ืฉืืงื ืึทืืืืึธืืื ื ืคึผืึธืกื ืืืจื ืกืืืคึผ ืืืขื ืืืจ ืฉืืขืื ืึท ืืืื ืกืขืจืืืขืจ, ืืื ืงืึทื ืคืืืืขืจื ืืืจื ืื ืฉืจืืคื.
ืฉืจืืคื ืงืึธื
# Change the hostname to be the same as the WordPress hostname
if [ ! "$(hostname)" == "${TLS_HOSTNAME}" ]; then
echo " Changing hostname to ${TLS_HOSTNAME}"
hostnamectl set-hostname "${TLS_HOSTNAME}"
fi
ืึทืืื ื ืืึธืกืื ืึทืืข ืฆื /etc/hosts
ืืขืจืฆื
ืฉืจืืคื ืงืึธื
# Add the hostname to /etc/hosts
if [ "$(grep -m1 "${TLS_HOSTNAME}" /etc/hosts)" = "" ]; then
echo " Adding hostname ${TLS_HOSTNAME} to /etc/hosts so that WordPress can ping itself"
printf "::1 %sn127.0.0.1 %sn" "${TLS_HOSTNAME}" "${TLS_HOSTNAME}" >> /etc/hosts
fi
ืื ืกืืึธืืื ื ืื ืืืฉืืจืื ืคืืจืืื ืื ืคึฟืึทืจ ืกืึทืืกืึทืงืืืึทื ื ืกืืขืคึผืก
ืื ืจืขืฉื ืคืื ืื ืฉืจืืคื ืจืืงืืืืืขืจื ืขืืืขืืข ืืืืื ืืื ืึทืกืืื ืึทื ืื ืจืืคึผืึทืืึทืืึธืจืื ืืขื ืขื ืืขืจืืืึทื ืืืงื. ืืืจ ืืขืจืืืึทื ืืืงื ืื ืจืฉืืื ืคืื ืจืืคึผืึทืืึทืืึธืจืื ืืื ืื ืกืืึทืืืจื ืื ื ืืืืืง ืืืฉืืจืื:
ืฉืจืืคื ืงืึธื
# Make sure tools needed for install are present
echo " Installing prerequisite tools"
apt-get -qq update
apt-get -qq install -y
bc
ca-certificates
coreutils
curl
gnupg2
lsb-release
ืึทืืื ื ืื NGINX Unit ืืื NGINX ืจืืคึผืึทืืึทืืึธืจืื
ืืขืจ ืฉืจืืคื ืื ืกืืึธืื NGINX Unit ืืื ืึธืคึฟื ืืงืืจ NGINX ืคึฟืื ืื ืืึทืึทืืืขืจ NGINX ืจืืคึผืึทืืึทืืึธืจืื ืฆื ืขื ืฉืืจ ืึทื ืื ืืืขืจืกืืขืก ืืื ืื ืืขืฆืืข ืืืืขืจืืืื ืืขืจืืืึทื ืืืงืื ืืขื ืืื ืืฉืืง ืคืืงืกืื ืืขื ืขื ืืขื ืืฆื.
ืืขืจ ืฉืจืืคื ืืืกืืฃ ืื NGINX Unit ืจืืคึผืึทืืึทืืึธืจื ืืื ืืขืจื ืึธื ืื NGINX ืจืืคึผืึทืืึทืืึธืจื, ืึทืืื ื ืื ืจืืคึผืึทืืึทืืึธืจืื ืฉืืืกื ืืื ืกืขืืืื ืืก ืืขืงืขืก apt
, ืืืคืืื ืื ื ืึทืงืกืขืก ืฆื ืจืืคึผืึทืืึทืืึธืจืื ืืืจื ืื ืืื ืืขืจื ืขื.
ืื ืคืึทืงืืืฉ ืืึทื ืืึธื ืืืจืื ื ืคืื ืื NGINX Unit ืืื NGINX ืึทืงืขืจื ืืื ืืขืจ ืืืืึทืืขืจ ืึธืคึผืืืืืื ื. ืืืจ ืคืึทืจ-ืืืืื ืจืืคึผืึทืืึทืืึธืจืื ืฆื ืืืกืืืืื ืึทืคึผืืืืืื ื ืืขืืึทืืึทืืึท ืขืืืขืืข ืืึธื, ืืืื ืื ืกืืึทืืืจืื ื ืคืึทืกืืขืจ.
ืฉืจืืคื ืงืึธื
# Install the NGINX Unit repository
if [ ! -f /etc/apt/sources.list.d/unit.list ]; then
echo " Installing NGINX Unit repository"
curl -fsSL https://nginx.org/keys/nginx_signing.key | apt-key add -
echo "deb https://packages.nginx.org/unit/ubuntu/ $(lsb_release -cs) unit" > /etc/apt/sources.list.d/unit.list
fi
# Install the NGINX repository
if [ ! -f /etc/apt/sources.list.d/nginx.list ]; then
echo " Installing NGINX repository"
curl -fsSL https://nginx.org/keys/nginx_signing.key | apt-key add -
echo "deb https://nginx.org/packages/mainline/ubuntu $(lsb_release -cs) nginx" > /etc/apt/sources.list.d/nginx.list
fi
ืื ืกืืึธืืื ื NGINX, NGINX Unit, PHP MariaDB, Certbot (ืืื ืก ืขื ืงืจืืคึผื) ืืื ืืืืขืจ ืืืคึผืขื ืืึทื ืกืื
ืึทืืึธื ืึทืืข ืื ืจืืคึผืึทืืึทืืึธืจืื ืืขื ืขื ืืืกืืฃ, ืืืจ ืืขืจืืืึทื ืืืงื ืื ืืขืืึทืืึทืืึท ืืื ืื ืกืืึทืืืจื ืื ืึทืคึผืืึทืงืืืฉืึทื ื. ืื ืคึผืึทืงืึทืืืฉืึทื ืืื ืกืืึทืืืจื ืืืจื ืื ืฉืจืืคื ืืืื ืึทืจืืึทื ื ืขืืขื PHP ืืงืกืืขื ืฉืึทื ื ืจืขืงืึทืืขื ืืื ืืืขื ืคืืืกื ืืืง WordPress.org
ืฉืจืืคื ืงืึธื
echo " Updating repository metadata"
apt-get -qq update
# Install PHP with dependencies and NGINX Unit
echo " Installing PHP, NGINX Unit, NGINX, Certbot, and MariaDB"
apt-get -qq install -y --no-install-recommends
certbot
python3-certbot-nginx
php-cli
php-common
php-bcmath
php-curl
php-gd
php-imagick
php-mbstring
php-mysql
php-opcache
php-xml
php-zip
ghostscript
nginx
unit
unit-php
mariadb-server
ืืึทืฉืืขืืืงื PHP ืคึฟืึทืจ ื ืืฆื ืืื NGINX Unit ืืื WordPress
ืืขืจ ืฉืจืืคื ืงืจืืืืฅ ืึท ืกืขืืืื ืืก ืืขืงืข ืืื ืื ืืืขืืืืืึทืืขืจ ืงืึธื ืค.ื. ืืึธืก ืฉืืขืื ืื ืืึทืงืกืืืื ืืขืงืข ืืคึผืืึธืึทื ืืจืืืก ืคึฟืึทืจ PHP, ืื ืืืืึทืื ืคืคึผ ืขืจืจืึธืจืก ืฆื ืืืื ืคึผืจืึธืืืงืฆืืข ืฆื STDERR ืึทืืื ืืื ืืืขืื ืืืื ืืึธืื ืฆื ืื NGINX ืืื ืื, ืืื ืจืืกืืึทืจื ืื NGINX ืืื ืื.
ืฉืจืืคื ืงืึธื
# Find the major and minor PHP version so that we can write to its conf.d directory
PHP_MAJOR_MINOR_VERSION="$(php -v | head -n1 | cut -d' ' -f2 | cut -d'.' -f1,2)"
if [ ! -f "/etc/php/${PHP_MAJOR_MINOR_VERSION}/embed/conf.d/30-wordpress-overrides.ini" ]; then
echo " Configuring PHP for use with NGINX Unit and WordPress"
# Add PHP configuration overrides
cat > "/etc/php/${PHP_MAJOR_MINOR_VERSION}/embed/conf.d/30-wordpress-overrides.ini" << EOM
; Set a larger maximum upload size so that WordPress can handle
; bigger media files.
upload_max_filesize=${UPLOAD_MAX_FILESIZE}
post_max_size=${UPLOAD_MAX_FILESIZE}
; Write error log to STDERR so that error messages show up in the NGINX Unit log
error_log=/dev/stderr
EOM
fi
# Restart NGINX Unit because we have reconfigured PHP
echo " Restarting NGINX Unit"
service unit restart
ืืึทืฉืืขืืืงื MariaDB ืืึทืืึทืืึทืกืข ืกืขืืืื ืืก ืคึฟืึทืจ ืืืึธืจืืคึผืจืขืกืก
ืืืจ ืืืืกืืขืจืืืืืื MariaDB ืืืืขืจ MySQL ืืืืึทื ืขืก ืืื ืืขืจ ืงืื ืึทืงืืืืืืืขืื ืืื ืงืขื ืขื ืืืื
ืืขืจ ืฉืจืืคื ืงืจืืืืฅ ืึท ื ืืึทืข ืืึทืืึทืืืืก ืืื ืงืจืืืืฅ ืืืึธืจืืคึผืจืขืกืก ืึทืงืกืขืก ืงืจืึทืืขื ืืฉืึทืื ืืืจื ืื ืืืคึผืืึทืงืง ืฆืืืื ื:
ืฉืจืืคื ืงืึธื
# Set up the WordPress database
echo " Configuring MariaDB for WordPress"
mysqladmin create wordpress || echo "Ignoring above error because database may already exist"
mysql -e "GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"localhost" IDENTIFIED BY "$WORDPRESS_DB_PASSWORD"; FLUSH PRIVILEGES;"
ืื ืกืืึธืืื ื ืื WordPress CLI ืคึผืจืึธืืจืึทื
ืืื ืืขื ืฉืจืื ืื ืฉืจืืคื ืื ืกืืึธืื ืื ืคึผืจืึธืืจืึทื
ืฉืจืืคื ืงืึธื
if [ ! -f /usr/local/bin/wp ]; then
# Install the WordPress CLI
echo " Installing the WordPress CLI tool"
curl --retry 6 -Ls "https://github.com/wp-cli/wp-cli/releases/download/v${WORDPRESS_CLI_VERSION}/wp-cli-${WORDPRESS_CLI_VERSION}.phar" > /usr/local/bin/wp
echo "$WORDPRESS_CLI_MD5 /usr/local/bin/wp" | md5sum -c -
chmod +x /usr/local/bin/wp
fi
ืื ืกืืึธืืื ื ืืื ืงืึทื ืคืืืืขืจ ืืืึธืจืืคึผืจืขืกืก
ืืขืจ ืฉืจืืคื ืื ืกืืึธืื ืื ืืขืฆืืข ืืืขืจืกืืข ืคืื โโืืืึธืจืืคึผืจืขืกืก ืืื ืื ืืืขืืืืืึทืืขืจ /var/www/wordpress
, ืืื ืืืื ืขื ืืขืจืื ืืขื ืื ืกืขืืืื ืืก:
- ืื ืืึทืืึทืืืืก ืงืฉืจ ืึทืจืืขื ืืืืขืจ ืึท ืืื ืืงืก ืคืขืื ืืึธืืขื ืึทื ืฉืืึธื ืคืื TCP ืืืืฃ ืืืคึผืืึทืงืง ืฆื ืจืขืืืฆืืจื TCP ืคืึทืจืงืขืจ.
- ืืืึธืจืืคึผืจืขืกืก ืืืกืืฃ ืึท ืคึผืจืขืคืืงืก https:// ืฆื ืื URL ืืืื ืงืืืืึทื ืฅ ืคืึทืจืืื ืื ืฆื NGINX ืืืืขืจ ืืืืคึผืก, ืืื ืืืื ืกืขื ืื ืื ืืืืึทื ืืึธืกืื ืึทืืข (ืืื ืฆืืืขืฉืืขืื ืืืจื NGINX) ืฆื PHP. ืืืจ ื ืืฆื ืึท ืฉืืืง ืคืื ืงืึธื ืฆื ืืึทืฉืืขืืืงื ืืขื.
- ืืืึธืจืืคึผืจืขืกืก ืืึทืจืฃ ืืืืคึผืก ืฆื ืืึธืืื
- URL ืกืืจืืงืืืจ ืืื ืืืฉืืืงืข ืืืื ืืืืืจื
- ืจืืืืืง ืืขืงืข ืกืืกืืขื ืคึผืขืจืืืฉืึทื ื ืืขื ืขื ืืึทืฉืืืื ืคึฟืึทืจ ืื ืืืึธืจืืคึผืจืขืกืก ืืืขืืืืืึทืืขืจ.
ืฉืจืืคื ืงืึธื
if [ ! -d /var/www/wordpress ]; then
# Create WordPress directories
mkdir -p /var/www/wordpress
chown -R www-data:www-data /var/www
# Download WordPress using the WordPress CLI
echo " Installing WordPress"
su -s /bin/sh -c 'wp --path=/var/www/wordpress core download' www-data
WP_CONFIG_CREATE_CMD="wp --path=/var/www/wordpress config create --extra-php --dbname=wordpress --dbuser=wordpress --dbhost="localhost:/var/run/mysqld/mysqld.sock" --dbpass="${WORDPRESS_DB_PASSWORD}""
# This snippet is injected into the wp-config.php file when it is created;
# it informs WordPress that we are behind a reverse proxy and as such
# allows it to generate links using HTTPS
cat > /tmp/wp_forwarded_for.php << 'EOM'
/* Turn HTTPS 'on' if HTTP_X_FORWARDED_PROTO matches 'https' */
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
$_SERVER['HTTPS'] = 'on';
}
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}
EOM
# Create WordPress configuration
su -s /bin/sh -p -c "cat /tmp/wp_forwarded_for.php | ${WP_CONFIG_CREATE_CMD}" www-data
rm /tmp/wp_forwarded_for.php
su -s /bin/sh -p -c "wp --path=/var/www/wordpress config set 'FORCE_SSL_ADMIN' 'true'" www-data
# Install WordPress
WP_SITE_INSTALL_CMD="wp --path=/var/www/wordpress core install --url="${WORDPRESS_URL}" --title="${WORDPRESS_SITE_TITLE}" --admin_user="${WORDPRESS_ADMIN_USER}" --admin_password="${WORDPRESS_ADMIN_PASSWORD}" --admin_email="${WORDPRESS_ADMIN_EMAIL}" --skip-email"
su -s /bin/sh -p -c "${WP_SITE_INSTALL_CMD}" www-data
# Set permalink structure to a sensible default that isn't in the UI
su -s /bin/sh -p -c "wp --path=/var/www/wordpress option update permalink_structure '/%year%/%monthnum%/%postname%/'" www-data
# Remove sample file because it is cruft and could be a security problem
rm /var/www/wordpress/wp-config-sample.php
# Ensure that WordPress permissions are correct
find /var/www/wordpress -type d -exec chmod g+s {} ;
chmod g+w /var/www/wordpress/wp-content
chmod -R g+w /var/www/wordpress/wp-content/themes
chmod -R g+w /var/www/wordpress/wp-content/plugins
fi
ืืึทืฉืืขืืืงื ืื NGINX ืึทืคึผืึทืจืึทื
ืืขืจ ืฉืจืืคื ืงืึทื ืคืืืืขืจ NGINX Unit ืฆื ืืืืคื PHP ืืื ืฉืขืคึผื ืืืึธืจืืคึผืจืขืกืก ืคึผืึทืืก, ืืืกืึทืืืืืื ื ืื ื ืึธืืขื ืคืื PHP ืคึผืจืึทืกืขืกืึทื ืืื ืึธืคึผืืืืืืื ื ืคืึธืจืฉืืขืืื ื ืกืขืืืื ืืก. ืขืก ืืขื ืขื ืืจืื ืคึฟืขืึดืงืืืื ืืืึธืก ืืขื ืขื ืืืขืจื ืฆื ืืึทืฆืึธืื ืืคืืขืจืงืืึทืืงืืื ืฆื:
- ื ืึทืืขืกืคึผืึทืกืข ืฉืืืฆื ืืื ืืืฉืืืกื ืืืจื ืฆืืฉืืึทื ื, ืืืืืจื ืืืืฃ ืงืึธื ืืจืึธืืืจืื ื ืึทื ืื ืฉืจืืคื ืืื ืคืืืกื ืืืง ืืื ืืขื ืงืึทื ืืืื ืขืจ. ืืึธืก ืืื ื ืืืืืง ืืืืึทื ืจืืึฟ ืงืึทื ืืืื ืขืจ ืกืขืืึทืคึผืก ืฉืืืฆื ื ืืฉื ื ืขืกืืขื ืคืืืกื ืืืง ืคืื ืงืึทื ืืืื ืขืจื.
- ืืืื ืขืก ืืื ืฉืืืฆื ืคึฟืึทืจ ื ืึทืืขืกืคึผืึทืกืขืก, ืื ื ืึทืืขืกืคึผืึทืกืข ืืื ืคืึทืจืงืจืืคึผืื ื ืขืฅ. ืืึธืก ืืื ื ืืืืืง ืฆื ืืึธืื ืืืึธืจืืคึผืจืขืกืก ืฆื ืกืืืืึทืืืืื ืืึทืกืื ืคืึทืจืืื ืื ืฆื ืขื ืืคึผืืื ืฅ ืืื ืืืื ืฆืืืจืืืืขื ืืืืฃ ืืขืจ ืืื ืืขืจื ืขืฅ.
- ืื ืืึทืงืกืืืื ื ืืืขืจ ืคืื ืคึผืจืึทืกืขืกืึทื ืืื ืืืฉืืืกื ืืื ืืืื: (ืคืึทืจืึทื ืขื ืืึผืจืื ืคึฟืึทืจ ืคืืืกื ืืืง MariaDB ืืื NGINX Uniy) / (ืืึทืจืึทื ืฉืืขืืจ ืืื PHP + 5)
ืืขืจ ืืืขืจื ืืื ืืึทืฉืืืื ืืื ืื NGINX Unit ืกืขืืืื ืืก.
ืืขืจ ืืืขืจื ืืืื ืืืคึผืืืื ืึทื ืขืก ืืขื ืขื ืฉืืขื ืืืง ืืืึท ืืื ืืกืืขืจ ืฆืืืื PHP ืคึผืจืึทืกืขืกืึทื ืคืืืกื ืืืง, ืืืึธืก ืืื ืืืืืืืง ืืืืึทื ืืืึธืจืืคึผืจืขืกืก ืืืื ืึท ืคึผืืึทืฅ ืคืื ืืืกืื ืืงืจืึทื ืึทืก ืจืืงืืืขืก ืฆื ืืื, ืืื ืึธื ื ืึธื ืคึผืจืึทืกืขืกืึทื ืคืืืกื ืืืง, ืืืฉื, WP-Cron ืืืขื ืืจืขืื. ืืืจ ืงืขื ืืืขืื ืฆื ืคืึทืจืืจืขืกืขืจื ืึธืืขืจ ืคืึทืจืืื ืขืจื ืื ืืืืึทืฅ ืืืืืจื ืืืืฃ ืืืื ืืืืข ืกืขืืืื ืืก, ืืืืึทื ืื ืกืขืืืื ืืก ืืืฉืืคื ืืึธ ืืขื ืขื ืงืึธื ืกืขืจืืืึทืืืืืข. ืืื ืจืืึฟ ืคึผืจืึธืืืงืฆืืข ืกืืกืืขืืขื, ืื ืกืขืืืื ืืก ืืขื ืขื ืฆืืืืฉื 10 ืืื 100.
ืฉืจืืคื ืงืึธื
if [ "${container:-unknown}" != "lxc" ] && [ "$(grep -m1 -a container=lxc /proc/1/environ | tr -d '')" == "" ]; then
NAMESPACES='"namespaces": {
"cgroup": true,
"credential": true,
"mount": true,
"network": false,
"pid": true,
"uname": true
}'
else
NAMESPACES='"namespaces": {}'
fi
PHP_MEM_LIMIT="$(grep 'memory_limit' /etc/php/7.4/embed/php.ini | tr -d ' ' | cut -f2 -d= | numfmt --from=iec)"
AVAIL_MEM="$(grep MemAvailable /proc/meminfo | tr -d ' kB' | cut -f2 -d: | numfmt --from-unit=K)"
MAX_PHP_PROCESSES="$(echo "${AVAIL_MEM}/${PHP_MEM_LIMIT}+5" | bc)"
echo " Calculated the maximum number of PHP processes as ${MAX_PHP_PROCESSES}. You may want to tune this value due to variations in your configuration. It is not unusual to see values between 10-100 in production configurations."
echo " Configuring NGINX Unit to use PHP and WordPress"
cat > /tmp/wordpress.json << EOM
{
"settings": {
"http": {
"header_read_timeout": 30,
"body_read_timeout": 30,
"send_timeout": 30,
"idle_timeout": 180,
"max_body_size": $(numfmt --from=iec ${UPLOAD_MAX_FILESIZE})
}
},
"listeners": {
"127.0.0.1:8080": {
"pass": "routes/wordpress"
}
},
"routes": {
"wordpress": [
{
"match": {
"uri": [
"*.php",
"*.php/*",
"/wp-admin/"
]
},
"action": {
"pass": "applications/wordpress/direct"
}
},
{
"action": {
"share": "/var/www/wordpress",
"fallback": {
"pass": "applications/wordpress/index"
}
}
}
]
},
"applications": {
"wordpress": {
"type": "php",
"user": "www-data",
"group": "www-data",
"processes": {
"max": ${MAX_PHP_PROCESSES},
"spare": 1
},
"isolation": {
${NAMESPACES}
},
"targets": {
"direct": {
"root": "/var/www/wordpress/"
},
"index": {
"root": "/var/www/wordpress/",
"script": "index.php"
}
}
}
}
}
EOM
curl -X PUT --data-binary @/tmp/wordpress.json --unix-socket /run/control.unit.sock http://localhost/config
ืืึทืฉืืขืืืงื NGINX
ืงืึทื ืคืืืืขืจ ืืงืขืจืืืง NGINX ืกืขืืืื ืืก
ืืขืจ ืฉืจืืคื ืงืจืืืืฅ ืึท ืืืขืืืืืึทืืขืจ ืคึฟืึทืจ ืื NGINX ืงืึทืฉ ืืื ืืขืืึธืื ืงืจืืืืฅ ืื ืืืืคึผื ืงืึทื ืคืืืืขืจืืืฉืึทื ืืขืงืข nginx.conf
. ืืึทืฆืึธืื ืืคืืขืจืงืืึทืืงืืึทื ืฆื ืื ื ืืืขืจ ืคืื ืืึทื ืืืขืจ ืคึผืจืึทืกืขืกืึทื ืืื ืื ืืึทืงืกืืืื ืืขืงืข ืืจืืืก ืืึทืฉืืขืืืงื ืคึฟืึทืจ ืืจืืคืงืืคืืข. ืขืก ืืื ืืืื ืึท ืฉืืจื ืืืืฃ ืืืึธืก ืื ืงืึทืืคึผืจืขืฉืึทื ืกืขืืืื ืืก ืืขืงืข, ืืืคืืื ื ืืื ืืขืจ ืืืืึทืืขืจ ืึธืคึผืืืืืื ื, ืืื ืงืึธื ื ืขืงืืขื, ื ืืืืขืืื ืืขื ืืืจื ืงืึทืืฉืื ื ืกืขืืืื ืืก.
ืฉืจืืคื ืงืึธื
# Make directory for NGINX cache
mkdir -p /var/cache/nginx/proxy
echo " Configuring NGINX"
cat > ${NGINX_CONF_DIR}/nginx.conf << EOM
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include ${NGINX_CONF_DIR}/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
client_max_body_size ${UPLOAD_MAX_FILESIZE};
keepalive_timeout 65;
# gzip settings
include ${NGINX_CONF_DIR}/gzip_compression.conf;
# Cache settings
proxy_cache_path /var/cache/nginx/proxy
levels=1:2
keys_zone=wp_cache:10m
max_size=10g
inactive=60m
use_temp_path=off;
include ${NGINX_CONF_DIR}/conf.d/*.conf;
}
EOM
ืืึทืฉืืขืืืงื NGINX ืงืึทืืคึผืจืขืฉืึทื
ืงืึทืืคึผืจืขืกืื ื ืืื ืืึทืื ืืืืฃ ืื ืคืืืขื ืืืืืขืจ ืฉืืงื ืขืก ืฆื ืงืืืืึทื ืฅ ืืื ืึท ืืจืืืก ืืืขื ืฆื ืคึฟืึทืจืืขืกืขืจื ืคึผืืึทืฅ ืคืึธืจืฉืืขืืื ื, ืึธืืขืจ ืืืืื ืืืื ืงืึทืืคึผืจืขืฉืึทื ืืื ืงืึทื ืคืืืืขืจื ืจืืืืืง. ืืขืจ ืึธืคึผืืืืืื ื ืคืื ืื ืฉืจืืคื ืืื ืืืืืจื ืืืืฃ ืื ืกืขืืืื ืืก
ืฉืจืืคื ืงืึธื
cat > ${NGINX_CONF_DIR}/gzip_compression.conf << 'EOM'
# Credit: https://github.com/h5bp/server-configs-nginx/
# ----------------------------------------------------------------------
# | Compression |
# ----------------------------------------------------------------------
# https://nginx.org/en/docs/http/ngx_http_gzip_module.html
# Enable gzip compression.
# Default: off
gzip on;
# Compression level (1-9).
# 5 is a perfect compromise between size and CPU usage, offering about 75%
# reduction for most ASCII files (almost identical to level 9).
# Default: 1
gzip_comp_level 6;
# Don't compress anything that's already small and unlikely to shrink much if at
# all (the default is 20 bytes, which is bad as that usually leads to larger
# files after gzipping).
# Default: 20
gzip_min_length 256;
# Compress data even for clients that are connecting to us via proxies,
# identified by the "Via" header (required for CloudFront).
# Default: off
gzip_proxied any;
# Tell proxies to cache both the gzipped and regular version of a resource
# whenever the client's Accept-Encoding capabilities header varies;
# Avoids the issue where a non-gzip capable client (which is extremely rare
# today) would display gibberish if their proxy gave them the gzipped version.
# Default: off
gzip_vary on;
# Compress all output labeled with one of the following MIME-types.
# `text/html` is always compressed by gzip module.
# Default: text/html
gzip_types
application/atom+xml
application/geo+json
application/javascript
application/x-javascript
application/json
application/ld+json
application/manifest+json
application/rdf+xml
application/rss+xml
application/vnd.ms-fontobject
application/wasm
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/eot
font/otf
font/ttf
image/bmp
image/svg+xml
text/cache-manifest
text/calendar
text/css
text/javascript
text/markdown
text/plain
text/xml
text/vcard
text/vnd.rim.location.xloc
text/vtt
text/x-component
text/x-cross-domain-policy;
EOM
ืืึทืฉืืขืืืงื NGINX ืคึฟืึทืจ ืืืึธืจืืคึผืจืขืกืก
ืืขืจื ืึธื, ืืขืจ ืฉืจืืคื ืงืจืืืืฅ ืึท ืงืึทื ืคืืืืขืจืืืฉืึทื ืืขืงืข ืคึฟืึทืจ ืืืึธืจืืคึผืจืขืกืก default.conf ืืื ืืขื ืงืึทืืึทืืึธื ืงืึธื ืค.ื. ืืึธ ืขืก ืืื ืงืึทื ืคืืืืขืจื:
- ืึทืงืืึทืืืืืืื ื TLS ืกืขืจืืืคืืงืึทืฅ ืืืงืืืขื ืคืื Let's Encrypt ืืืจื Certbot (ืงืึทื ืคืืืืขืจืื ื ืขืก ืืืขื ืืืื ืืื ืืขืจ ืืืืึทืืขืจ ืึธืคึผืืืืืื ื)
- ืงืึทื ืคืืืืขืจ TLS ืืืืขืจืืืื ืกืขืืืื ืืก ืืืืืจื ืืืืฃ ืจืขืงืึทืืึทื ืืืืฉืึทื ื ืคืื Let's Encrypt
- ืืขืื ืกืงืืคึผื ืืขืื ืงืึทืืฉืื ื ืคึฟืึทืจ 1 ืฉืขื ืืืจื ืคืขืืืงืืึทื
- ืืืกืืืืึทื ืึทืงืกืขืก ืืึธืืื ื, ืืื ืืขืืื ื ืืื ืืขืืช ืืึธืืื ื ืืืื ืื ืืขืงืข ืืื ื ืื ืืขืคึฟืื ืขื, ืคึฟืึทืจ ืฆืืืื ืคึผืจืึธืกื ืืขืืขืื ืืขืงืขืก: favicon.ico ืืื robots.txt
- ืืืืงืขื ืขื ืฆืืืจืื ืฆื ืคืึทืจืืึธืจืื ืืขืงืขืก ืืื ืขืืืขืืข ืืขืงืขืก .ืคืคึผืฆื ืคืึทืจืืืึทืื ืืืืขืืึทื ืึทืงืกืขืก ืึธืืขืจ ืึทื ืื ืืขื ืฉืึทื ืึทื ืงืึทืืขืจ
- ืืืกืืืืึทื ืึทืงืกืขืก ืืึธืืื ื ืคึฟืึทืจ ืกืืึทืืืง ืืื ืฉืจืืคึฟื ืืขืงืขืก
- ืืึทืฉืืขืืืงื ืืขื ืืืื
ืึทืงืกืขืก-ืงืึธื ืืจืึธื-ืึทืืึทื-ืึธืจืืืื ืคึฟืึทืจ ืฉืจืืคึฟื ืืขืงืขืก - ืึทืืื ื ืจืืืื ื ืคึฟืึทืจ index.php ืืื ืื ืืขืจืข ืกืืึทืืืงืก.
ืฉืจืืคื ืงืึธื
cat > ${NGINX_CONF_DIR}/conf.d/default.conf << EOM
upstream unit_php_upstream {
server 127.0.0.1:8080;
keepalive 32;
}
server {
listen 80;
listen [::]:80;
# ACME-challenge used by Certbot for Let's Encrypt
location ^~ /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://${TLS_HOSTNAME}$request_uri;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name ${TLS_HOSTNAME};
root /var/www/wordpress/;
# Let's Encrypt configuration
ssl_certificate ${CERT_DIR}/fullchain.pem;
ssl_certificate_key ${CERT_DIR}/privkey.pem;
ssl_trusted_certificate ${CERT_DIR}/chain.pem;
include ${NGINX_CONF_DIR}/options-ssl-nginx.conf;
ssl_dhparam ${NGINX_CONF_DIR}/ssl-dhparams.pem;
# OCSP stapling
ssl_stapling on;
ssl_stapling_verify on;
# Proxy caching
proxy_cache wp_cache;
proxy_cache_valid 200 302 1h;
proxy_cache_valid 404 1m;
proxy_cache_revalidate on;
proxy_cache_background_update on;
proxy_cache_lock on;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd,
# .DS_Store (Mac)
# Keep logging the requests to parse later (or to pass to firewall utilities
# such as fail2ban)
location ~ /. {
deny all;
}
# Deny access to any files with a .php extension in the uploads directory;
# works in subdirectory installs and also in multi-site network.
# Keep logging the requests to parse later (or to pass to firewall utilities
# such as fail2ban).
location ~* /(?:uploads|files)/.*.php$ {
deny all;
}
# WordPress: deny access to wp-content, wp-includes PHP files
location ~* ^/(?:wp-content|wp-includes)/.*.php$ {
deny all;
}
# Deny public access to wp-config.php
location ~* wp-config.php {
deny all;
}
# Do not log access for static assets, media
location ~* .(?:css(.map)?|js(.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
access_log off;
}
location ~* .(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
add_header Access-Control-Allow-Origin "*";
access_log off;
}
location / {
try_files $uri @index_php;
}
location @index_php {
proxy_socket_keepalive on;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_pass http://unit_php_upstream;
}
location ~* .php$ {
proxy_socket_keepalive on;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
try_files $uri =404;
proxy_pass http://unit_php_upstream;
}
}
EOM
ืงืึทื ืคืืืืขืจ Certbot ืคึฟืึทืจ ืืื ืก ืขื ืงืจืืคึผื ืกืขืจืืืคืืงืึทืฅ ืืื ืืืืืึธืืึทืืืฉ ืจืื ืืื ื ืืื
- ืกืืึทืคึผืก NGINX
- ืืึทืื ืืึธืืื ืจืขืงืึทืืขื ืืื TLS ืกืขืืืื ืืก
- ืืืืคื Certbot ืฆื ืืึทืงืืืขื ืกืขืจืืืคืืงืึทืฅ ืคึฟืึทืจ ืืขื ืคึผืืึทืฅ
- ืจืืกืืึทืจื NGINX ืฆื ื ืืฆื ืกืขืจืืืคืืงืึทืฅ
- ืงืึทื ืคืืืืขืจ ืกืขืจืืืึธื ืฆื ืืืืคื ืืขืืืขื ืืืึท 3:24 ืฆื ืงืึธื ืืจืึธืืืจื ืคึฟืึทืจ ืืึทืืืืึทืื ืจืื ืืึทืื ืืื, ืืืื ื ืืืืืง, ืืจืืคืงืืคืืข ื ืืึท ืกืขืจืืืคืืงืึทืฅ ืืื ืจืืกืืึทืจื NGINX.
ืฉืจืืคื ืงืึธื
echo " Stopping NGINX in order to set up Let's Encrypt"
service nginx stop
mkdir -p /var/www/certbot
chown www-data:www-data /var/www/certbot
chmod g+s /var/www/certbot
if [ ! -f ${NGINX_CONF_DIR}/options-ssl-nginx.conf ]; then
echo " Downloading recommended TLS parameters"
curl --retry 6 -Ls -z "Tue, 14 Apr 2020 16:36:07 GMT"
-o "${NGINX_CONF_DIR}/options-ssl-nginx.conf"
"https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf"
|| echo "Couldn't download latest options-ssl-nginx.conf"
fi
if [ ! -f ${NGINX_CONF_DIR}/ssl-dhparams.pem ]; then
echo " Downloading recommended TLS DH parameters"
curl --retry 6 -Ls -z "Tue, 14 Apr 2020 16:49:18 GMT"
-o "${NGINX_CONF_DIR}/ssl-dhparams.pem"
"https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem"
|| echo "Couldn't download latest ssl-dhparams.pem"
fi
# If tls_certs_init.sh hasn't been run before, remove the self-signed certs
if [ ! -d "/etc/letsencrypt/accounts" ]; then
echo " Removing self-signed certificates"
rm -rf "${CERT_DIR}"
fi
if [ "" = "${LETS_ENCRYPT_STAGING:-}" ] || [ "0" = "${LETS_ENCRYPT_STAGING}" ]; then
CERTBOT_STAGING_FLAG=""
else
CERTBOT_STAGING_FLAG="--staging"
fi
if [ ! -f "${CERT_DIR}/fullchain.pem" ]; then
echo " Generating certificates with Let's Encrypt"
certbot certonly --standalone
-m "${WORDPRESS_ADMIN_EMAIL}"
${CERTBOT_STAGING_FLAG}
--agree-tos --force-renewal --non-interactive
-d "${TLS_HOSTNAME}"
fi
echo " Starting NGINX in order to use new configuration"
service nginx start
# Write crontab for periodic Let's Encrypt cert renewal
if [ "$(crontab -l | grep -m1 'certbot renew')" == "" ]; then
echo " Adding certbot to crontab for automatic Let's Encrypt renewal"
(crontab -l 2>/dev/null; echo "24 3 * * * certbot renew --nginx --post-hook 'service nginx reload'") | crontab -
fi
ื ืึธื ืงืืกืืึธืืืืึทืืืึธื ืคืื ืืืื ืคึผืืึทืฅ
ืืืจ ืืขืจืขืื ืืืืื ืืืขืื ืืื ืืื ืืืขืจ ืฉืจืืคื ืงืึทื ืคืืืืขืจ NGINX ืืื NGINX Unit ืฆื ืืื ืขื ืึท ืคึผืจืึธืืืงืฆืืข-ืืจืืื ืืืขืืืืืื ืืื TLSSSL ืขื ืืืืึทืื. ืืืจ ืงืขื ืืืื, ืืืคึผืขื ืืื ื ืืืืฃ ืืืื ืืืืขืจืคืขื ืืฉื, ืืืืื ืืื ืืขืจ ืฆืืงืื ืคึฟื:
- ืฉืืืฆื
ืืจืึธืืื , ืืืคึผืจืืืื ืืืืฃ-ืืขื-ืคืืืขื ืงืึทืืคึผืจืขืฉืึทื ืืืืขืจ ืืืืคึผืก ืืึธืืกืขืงืืจืืื ัืึผืืืื ืคึฟืึทืจ ืืืึธืจืืคึผืจืขืกืก ืฆื ืคืึทืจืืืึทืื ืึธืืึทืืืืืื ืื ืคืืื ืืืืฃ ืืืื ืคึผืืึทืฅืืึทืงืงืืคึผ ืคึฟืึทืจ ืืืึธืจืืคึผืจืขืกืก, ืคึผืึทืกืืง ืคึฟืึทืจ ืืืจืฉืืฅ ืืืจืืึทืคึผืคึผืึทืจืืึธืจ (ืืืืฃ ืืืื ืื)- ืคึผืึธืกืืคืืงืก ืึธืืขืจ ืืกืืืคึผ ืึทืืื ืืืึธืจืืคึผืจืขืกืก ืงืขื ืขื ืฉืืงื ืคึผืึธืกื
- ืงืึธื ืืจืึธืืืจื ืืืื ืคึผืืึทืฅ ืึทืืื ืืืจ ืคึฟืึทืจืฉืืืื ืืื ืคืื ืคืึทืจืงืขืจ ืขืก ืงืขื ืขื ืฉืขืคึผื
ืคึฟืึทืจ ืืคืืื ืืขืกืขืจ ืคึผืืึทืฅ ืคืึธืจืฉืืขืืื ื, ืืืจ ืจืขืงืึธืืขื ืืืจื ืึทืคึผืืจืืืืื ื ืฆื
ื ื ืคึฟืึทืจ ืฉืืืฆื ืคืื ืึท ืืืื-ืืึทืกืข ืืืขืืืืืื, ืืืจ ืงืขื ื ืงืึธื ืืึทืงื ืกืคึผืขืฉืึทืืึทืกืฅ
Southbridge . ืืืจ ืืืขืื ืขื ืฉืืจ ืฉื ืขื ืืื ืคืึทืจืืึธืืืขื ืึธืคึผืขืจืึทืฆืืข ืคืื โโืืืื ืืืขืืืืืื ืึธืืขืจ ืืื ืกื ืืื ืืขืจ ืงืืื ืืึทืกืข.
ืืงืืจ: www.habr.com