WordPress ์ค์น์ ๊ดํ ๋ง์ ์๋ฃ๊ฐ ์์ผ๋ฉฐ Google์์ โWordPress ์ค์นโ๋ฅผ ๊ฒ์ํ๋ฉด ์ฝ XNUMX๋ง ๊ฐ์ ๊ฒฐ๊ณผ๊ฐ ๋ฐํ๋ฉ๋๋ค. ๊ทธ๋ฌ๋ WordPress์ ๊ธฐ๋ณธ ์ด์ ์ฒด์ ๊ฐ ์ฅ๊ธฐ๊ฐ ์ง์๋ ์ ์๋๋ก ์ค์นํ๊ณ ๊ตฌ์ฑํ๋ ๋ฐ ๋์์ด ๋๋ ์ ์ฉํ ๊ฐ์ด๋๋ ์ค์ ๋ก ๊ฑฐ์ ์์ต๋๋ค. ์๋ง๋ ์ฌ๋ฐ๋ฅธ ์ค์ ์ ๊ทํ์ ํน์ ์๊ตฌ ์ฌํญ์ ํฌ๊ฒ ์ข์ฐ๋ ์๋ ์๊ณ , ์์ธํ ์ค๋ช ์ผ๋ก ์ธํด ๊ธฐ์ฌ๋ฅผ ์ฝ๊ธฐ๊ฐ ์ด๋ ค์์ก์ ์๋ ์์ต๋๋ค.
์ด ๊ธฐ์ฌ์์๋ ์ฐ๋ถํฌ์ WordPress๋ฅผ ์๋์ผ๋ก ์ค์นํ๋ bash ์คํฌ๋ฆฝํธ๋ฅผ ์ ๊ณตํ์ฌ ๋ ๊ฐ์ง ์ฅ์ ์ ๋ชจ๋ ๊ฒฐํฉํ๋ ค๊ณ ๋
ธ๋ ฅํ ๊ฒ์
๋๋ค. ๊ฐ ๋ถ๋ถ์ ๊ธฐ๋ฅ๊ณผ ๋์์ธ ์ ์ ์ถฉ์ ์ ์ค๋ช
ํ๋ฉด์ ์ด๋ฅผ ์ดํด๋ณด๊ฒ ์ต๋๋ค. ๊ทธ๊ฒ. ์๋ จ๋ ์ฌ์ฉ์๋ผ๋ฉด ๊ธฐ์ฌ ๋ณธ๋ฌธ์ ๊ฑด๋๋ฐ๊ณ ๊ทธ๋ฅ ์ฌ์ฉํด๋ ๋ฉ๋๋ค.
NGINX ์ ๋์ ์ฌ์ฉํ์ฌ WordPress๋ฅผ ๋ฐฐํฌํ๊ธฐ ์ํด ๊ฐ๋ฐ๋ ์ํคํ
์ฒ๋ ๋ค์ ํญ๋ชฉ์ ์ค๋ช
๋์ด ์์ต๋๋ค.
- ์๋ํ๋ ์ค CLI
- Let's Encrypt ๋ฐ TLSSSL ์ธ์ฆ์
- ์๋ ์ธ์ฆ์ ๊ฐฑ์
- NGINX ์บ์ฑ
- NGINX ์์ถ
- HTTPS ๋ฐ HTTP/2 ์ง์
- ํ๋ก์ธ์ค ์๋ํ
์ด ๊ธฐ์ฌ์์๋ ์ ์ ์ฒ๋ฆฌ ์๋ฒ, PHP ์ฒ๋ฆฌ ์๋ฒ ๋ฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋์์ ํธ์คํ ํ๋ ํ๋์ ์๋ฒ์ ์ค์นํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํฉ๋๋ค. ์ฌ๋ฌ ๊ฐ์ ํธ์คํธ ๋ฐ ์๋น์ค๋ฅผ ์ง์ํ๋ ์ค์น๋ ๋ฏธ๋์ ์ ์ฌ์ ์ธ ์ฃผ์ ์ ๋๋ค. ์ด ๊ธฐ์ฌ์ ์๋ ๋ด์ฉ์ ๋ํด ๊ธ์ ์ฐ๊ธธ ์ํ์๋ฉด ๋๊ธ์ ๋จ๊ฒจ์ฃผ์ธ์.
์๊ตฌ ์ฌํญ
- ์๋ฒ ์ปจํ
์ด๋(
LXC ๋๋Lxd ), ์ต์ 512MB RAM ๋ฐ Ubuntu 18.04 ์ด์์ด ์ต๊ทผ ์ค์น๋ ๊ฐ์ ๋จธ์ ๋๋ ์ผ๋ฐ ํ๋์จ์ด ์๋ฒ. - ์ธํฐ๋ท ์ ์ ๊ฐ๋ฅ ํฌํธ 80 ๋ฐ 443
- ์ด ์๋ฒ์ ๊ณต์ฉ IP ์ฃผ์์ ์ฐ๊ฒฐ๋ ๋๋ฉ์ธ ์ด๋ฆ
- ๋ฃจํธ ๊ถํ(sudo)์ผ๋ก ์ ๊ทผํฉ๋๋ค.
์ํคํ ์ฒ ๊ฐ์
์ํคํ
์ฒ๋ ์ค๋ช
๊ณผ ๋์ผํฉ๋๋ค.
์ผ๋ฐ ์์น
- ์คํฌ๋ฆฝํธ์ ๋ง์ ๊ตฌ์ฑ ๋ช ๋ น์ ๋ฉฑ๋ฑ์ฑ์ ์ํ if ์กฐ๊ฑด์ผ๋ก ๋ํ๋ฉ๋๋ค. ์ด๋ฏธ ์ค๋น๋ ์ค์ ์ ๋ณ๊ฒฝํ ์ํ ์์ด ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ๋ฌ ๋ฒ ์คํํ ์ ์์ต๋๋ค.
- ์คํฌ๋ฆฝํธ๋ ๋ฆฌํฌ์งํ ๋ฆฌ์์ ์ํํธ์จ์ด๋ฅผ ์ค์นํ๋ ค๊ณ ์๋ํ๋ฏ๋ก ํ๋์ ๋ช
๋ น์ผ๋ก ์์คํ
์
๋ฐ์ดํธ๋ฅผ ์ ์ฉํ ์ ์์ต๋๋ค(
apt upgrade
์ฐ๋ถํฌ์ ๊ฒฝ์ฐ). - ํ์ ์ปจํ ์ด๋์์ ์คํ ์ค์ธ์ง ๊ฐ์งํ์ฌ ๊ทธ์ ๋ฐ๋ผ ์ค์ ์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
- ์ค์ ์์ ์์ํ ์ค๋ ๋ ํ๋ก์ธ์ค ์๋ฅผ ์ค์ ํ๊ธฐ ์ํด ์คํฌ๋ฆฝํธ๋ ์ปจํ ์ด๋, ๊ฐ์ ๋จธ์ ๋ฐ ํ๋์จ์ด ์๋ฒ์์ ์๋ํ๊ธฐ ์ํ ์๋ ์ค์ ์ ์ถ์ธกํ๋ ค๊ณ ์๋ํฉ๋๋ค.
- ์ค์ ์ ์ค๋ช ํ ๋ ์ฐ๋ฆฌ๋ ํญ์ ์๋ํ๋ฅผ ๋จผ์ ์๊ฐํฉ๋๋ค. ์๋ํ๊ฐ ์ฝ๋ํ ์ธํ๋ผ๋ฅผ ๋ง๋๋ ๊ธฐ์ด๊ฐ ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
- ๋ชจ๋ ๋ช ๋ น์ ์ฌ์ฉ์๋ก๋ถํฐ ์คํ๋ฉ๋๋ค. ๋ฟ๋ฆฌ, ๊ธฐ๋ณธ ์์คํ ์ค์ ์ ๋ณ๊ฒฝํ๊ธฐ ๋๋ฌธ์ WordPress ์์ฒด๋ ์ผ๋ฐ ์ฌ์ฉ์๋ก ์คํ๋ฉ๋๋ค.
ํ๊ฒฝ ๋ณ์ ์ค์
์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๊ธฐ ์ ์ ๋ค์ ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํ์ญ์์ค.
WORDPRESS_DB_PASSWORD
โ WordPress ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋น๋ฐ๋ฒํธWORDPRESS_ADMIN_USER
- WordPress ๊ด๋ฆฌ์ ์ฌ์ฉ์ ์ด๋ฆWORDPRESS_ADMIN_PASSWORD
- WordPress ๊ด๋ฆฌ์ ๋น๋ฐ๋ฒํธWORDPRESS_ADMIN_EMAIL
โ WordPress ๊ด๋ฆฌ์ ์ด๋ฉ์ผWORDPRESS_URL
โ ๋ค์์ผ๋ก ์์ํ๋ WordPress ์ฌ์ดํธ์ ์ ์ฒด URLhttps://
.LETS_ENCRYPT_STAGING
โ ๊ธฐ๋ณธ์ ์ผ๋ก ๋น์ด ์์ง๋ง ๊ฐ์ 1๋ก ์ค์ ํ๋ฉด ์ค์ ์ ํ ์คํธํ ๋ ์ธ์ฆ์๋ฅผ ์์ฃผ ์์ฒญํ๋ ๋ฐ ํ์ํ Let's Encrypt์ ์คํ ์ด์ง ์๋ฒ๋ฅผ ์ฌ์ฉํ๊ฒ ๋ฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ๋ง์ ์์ฒญ์ผ๋ก ์ธํด Let's Encrypt๊ฐ ์ผ์์ ์ผ๋ก IP ์ฃผ์๋ฅผ ์ฐจ๋จํ ์ ์์ต๋๋ค.
์คํฌ๋ฆฝํธ๋ ์ด๋ฌํ WordPress ๊ด๋ จ ๋ณ์๊ฐ ์ค์ ๋์ด ์๋์ง ํ์ธํ๊ณ ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ ์ข
๋ฃ๋ฉ๋๋ค.
์คํฌ๋ฆฝํธ ์ค 572-576์์ ๊ฐ์ ํ์ธํฉ๋๋ค. LETS_ENCRYPT_STAGING
.
ํ์ ํ๊ฒฝ ๋ณ์ ์ค์
55-61ํ์ ์คํฌ๋ฆฝํธ๋ ํ๋ ์ฝ๋ฉ๋ ๊ฐ์ด๋ ์ด์ ์น์ ์์ ์ค์ ๋ ๋ณ์์์ ํ์๋ ๊ฐ์ ์ฌ์ฉํ์ฌ ๋ค์ ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํฉ๋๋ค.
DEBIAN_FRONTEND="noninteractive"
โ ์์ฉ ํ๋ก๊ทธ๋จ์ด ์คํฌ๋ฆฝํธ์์ ์คํ ์ค์ด๋ฉฐ ์ฌ์ฉ์ ์ํธ ์์ฉ ๊ฐ๋ฅ์ฑ์ด ์์์ ์๋ ค์ค๋๋ค.WORDPRESS_CLI_VERSION="2.4.0"
โ ์ ํ๋ฆฌ์ผ์ด์ ์ WordPress CLI ๋ฒ์ ์ ๋๋ค.WORDPRESS_CLI_MD5= "dedd5a662b80cda66e9e25d44c23b25c"
โ WordPress CLI 2.4.0 ์คํ ํ์ผ์ ์ฒดํฌ์ฌ(๋ฒ์ ์ ๋ณ์์ ํ์๋จ)WORDPRESS_CLI_VERSION
). 162ํ์ ์คํฌ๋ฆฝํธ๋ ์ด ๊ฐ์ ์ฌ์ฉํ์ฌ ์ฌ๋ฐ๋ฅธ WordPress CLI ํ์ผ์ด ๋ค์ด๋ก๋๋์๋์ง ํ์ธํฉ๋๋ค.UPLOAD_MAX_FILESIZE="16M"
โ WordPress์ ์ ๋ก๋ํ ์ ์๋ ์ต๋ ํ์ผ ํฌ๊ธฐ์ ๋๋ค. ์ด ์ค์ ์ ์ฌ๋ฌ ๊ณณ์์ ์ฌ์ฉ๋๊ธฐ ๋๋ฌธ์ ํ ๊ณณ์์ ์ค์ ํ๋ ๊ฒ์ด ๋ ์ฝ์ต๋๋ค.TLS_HOSTNAME= "$(echo ${WORDPRESS_URL} | cut -d'/' -f3)"
โ WORDPRESS_URL ๋ณ์์์ ์ถ์ถ๋ ์์คํ ํธ์คํธ ์ด๋ฆ. ๋ด๋ถ WordPress ํ์ธ๋ฟ๋ง ์๋๋ผ Let's Encrypt์์ ์ ์ ํ TLS/SSL ์ธ์ฆ์๋ฅผ ์ป๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.NGINX_CONF_DIR="/etc/nginx"
โ ๊ธฐ๋ณธ ํ์ผ์ ํฌํจํ์ฌ NGINX ์ค์ ์ด ์๋ ๋๋ ํฐ๋ฆฌ ๊ฒฝ๋กnginx.conf
.CERT_DIR="/etc/letsencrypt/live/${TLS_HOSTNAME}"
โ ๋ณ์์์ ์ป์ WordPress ์ฌ์ดํธ์ Let's Encrypt ์ธ์ฆ์ ๊ฒฝ๋กTLS_HOSTNAME
.
WordPress ์๋ฒ์ ํธ์คํธ ์ด๋ฆ ํ ๋น
์คํฌ๋ฆฝํธ๋ ๊ฐ์ด ์ฌ์ดํธ์ ๋๋ฉ์ธ ์ด๋ฆ๊ณผ ์ผ์นํ๋๋ก ์๋ฒ์ ํธ์คํธ ์ด๋ฆ์ ์ค์ ํฉ๋๋ค. ๊ผญ ํ์ํ ๊ฒ์ ์๋์ง๋ง, ์คํฌ๋ฆฝํธ์์ ๊ตฌ์ฑํ ๋๋ก ๋จ์ผ ์๋ฒ๋ฅผ ์ค์ ํ ๋ SMTP๋ฅผ ํตํด ๋ณด๋ด๋ ๋ฉ์ผ์ ๋ณด๋ด๋ ๊ฒ์ด ๋ ํธ๋ฆฌํฉ๋๋ค.
์คํฌ๋ฆฝํธ ์ฝ๋
# 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 ์ ๋ ๋ฐ NGINX ๋ฆฌํฌ์งํ ๋ฆฌ ์ถ๊ฐ
์ด ์คํฌ๋ฆฝํธ๋ ๊ณต์ NGINX ๋ฆฌํฌ์งํ ๋ฆฌ์์ NGINX ์ ๋๊ณผ ์คํ ์์ค NGINX๋ฅผ ์ค์นํ์ฌ ์ต์ ๋ณด์ ์ ๋ฐ์ดํธ ๋ฐ ๋ฒ๊ทธ ์์ ์ด ํฌํจ๋ ๋ฒ์ ์ด ์ฌ์ฉ๋๋๋ก ํฉ๋๋ค.
์คํฌ๋ฆฝํธ๋ NGINX ๋จ์ ์ ์ฅ์๋ฅผ ์ถ๊ฐํ ๋ค์ NGINX ์ ์ฅ์๋ฅผ ์ถ๊ฐํ๊ณ ์ ์ฅ์ ํค์ ์ค์ ํ์ผ์ ์ถ๊ฐํฉ๋๋ค. apt
, ์ธํฐ๋ท์ ํตํ ์ ์ฅ์์ ๋ํ ์ก์ธ์ค๋ฅผ ์ ์ํฉ๋๋ค.
NGINX ์ฅ์น์ 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 ์ ๋, PHP MariaDB, Certbot(Let's Encrypt) ๋ฐ ํด๋น ์ข ์์ฑ ์ค์น
๋ชจ๋ ๋ฆฌํฌ์งํ ๋ฆฌ๊ฐ ์ถ๊ฐ๋๋ฉด ๋ฉํ๋ฐ์ดํฐ๋ฅผ ์ ๋ฐ์ดํธํ๊ณ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ค์นํฉ๋๋ค. ์คํฌ๋ฆฝํธ๋ก ์ค์น๋ ํจํค์ง์๋ WordPress.org๋ฅผ ์คํํ ๋ ๊ถ์ฅ๋๋ PHP ํ์ฅ๋ ํฌํจ๋์ด ์์ต๋๋ค.
์คํฌ๋ฆฝํธ ์ฝ๋
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
NGINX ์ ๋ ๋ฐ WordPress์ ํจ๊ป ์ฌ์ฉํ PHP ์ค์
์คํฌ๋ฆฝํธ๋ ๋๋ ํฐ๋ฆฌ์ ์ค์ ํ์ผ์ ์์ฑํฉ๋๋ค. conf.d. ์ด๋ PHP์ ์ต๋ ํ์ผ ์ ๋ก๋ ํฌ๊ธฐ๋ฅผ ์ค์ ํ๊ณ , 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
WordPress์ฉ MariaDB ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ค์ ์ง์
์ฐ๋ฆฌ๋ MySQL ๋์ MariaDB๋ฅผ ์ ํํ์ต๋๋ค. ์๋ํ๋ฉด ์ปค๋ฎค๋ํฐ ํ๋์ด ๋ ๋ง๊ณ
์คํฌ๋ฆฝํธ๋ ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์์ฑํ๊ณ ๋ฃจํ๋ฐฑ ์ธํฐํ์ด์ค๋ฅผ ํตํด WordPress ์ก์ธ์ค ์๊ฒฉ ์ฆ๋ช ์ ์์ฑํฉ๋๋ค.
์คํฌ๋ฆฝํธ ์ฝ๋
# 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
WordPress ์ค์น ๋ฐ ๊ตฌ์ฑ
์คํฌ๋ฆฝํธ๋ ์ต์ ๋ฒ์ ์ WordPress๋ฅผ ๋๋ ํ ๋ฆฌ์ ์ค์นํฉ๋๋ค. /var/www/wordpress
, ๋ํ ์ค์ ์ ๋ณ๊ฒฝํฉ๋๋ค.
- ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ์ TCP ํธ๋ํฝ์ ์ค์ด๊ธฐ ์ํด ๋ฃจํ๋ฐฑ ์ TCP ๋์ Unix ๋๋ฉ์ธ ์์ผ์ ํตํด ์๋ํฉ๋๋ค.
- WordPress์ ์ ๋์ฌ ์ถ๊ฐ https:// ํด๋ผ์ด์ธํธ๊ฐ HTTPS๋ฅผ ํตํด NGINX์ ์ฐ๊ฒฐํ๋ ๊ฒฝ์ฐ URL์ ์ฐ๊ฒฐํ๊ณ ์๊ฒฉ ํธ์คํธ ์ด๋ฆ(NGINX์์ ์ ๊ณตํ ๋๋ก)์ PHP๋ก ๋ณด๋ ๋๋ค. ์ฐ๋ฆฌ๋ ์ด๊ฒ์ ์ค์ ํ๊ธฐ ์ํด ์ฝ๋๋ฅผ ์ฌ์ฉํฉ๋๋ค.
- WordPress์ ๋ก๊ทธ์ธํ๋ ค๋ฉด HTTPS๊ฐ ํ์ํฉ๋๋ค.
- URL ๊ตฌ์กฐ๋ ์๋์ผ๋ก ๋ฆฌ์์ค ๊ธฐ๋ฐ์ ๋๋ค.
- WordPress ๋๋ ํฐ๋ฆฌ์ ๋ํด ์ฌ๋ฐ๋ฅธ ํ์ผ ์์คํ ๊ถํ์ด ์ค์ ๋์ด ์์ต๋๋ค.
์คํฌ๋ฆฝํธ ์ฝ๋
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 ์ฅ์น ์ค์
์ด ์คํฌ๋ฆฝํธ๋ PHP๋ฅผ ์คํํ๊ณ WordPress ๊ฒฝ๋ก๋ฅผ ์ฒ๋ฆฌํ๋๋ก NGINX ์ ๋์ ๊ตฌ์ฑํ์ฌ PHP ํ๋ก์ธ์ค์ ๋ค์์คํ์ด์ค๋ฅผ ๊ฒฉ๋ฆฌํ๊ณ ์ฑ๋ฅ ์ค์ ์ ์ต์ ํํฉ๋๋ค. ์ฃผ๋ชฉํ ๋งํ ์ธ ๊ฐ์ง ๊ธฐ๋ฅ์ด ์์ต๋๋ค.
- ๋ค์์คํ์ด์ค ์ง์์ ์คํฌ๋ฆฝํธ๊ฐ ์ปจํ ์ด๋์์ ์คํ ์ค์ธ์ง ํ์ธํ๋ ์กฐ๊ฑด์ ๋ฐ๋ผ ๊ฒฐ์ ๋ฉ๋๋ค. ์ด๋ ๋๋ถ๋ถ์ ์ปจํ ์ด๋ ์ค์ ์ด ์ปจํ ์ด๋์ ์ค์ฒฉ ์คํ์ ์ง์ํ์ง ์๊ธฐ ๋๋ฌธ์ ํ์ํฉ๋๋ค.
- ๋ค์์คํ์ด์ค์ ๋ํ ์ง์์ด ์์ผ๋ฉด ๋ค์์คํ์ด์ค๊ฐ ๋นํ์ฑํ๋ฉ๋๋ค. ๋คํธ์ํฌ. ์ด๋ WordPress๊ฐ ์๋ํฌ์ธํธ์ ๋์์ ์ฐ๊ฒฐํ๊ณ ์ธํฐ๋ท์์ ์ก์ธ์คํ ์ ์๋๋ก ํ๋ ๋ฐ ํ์ํฉ๋๋ค.
- ์ต๋ ํ๋ก์ธ์ค ์๋ ๋ค์๊ณผ ๊ฐ์ด ๊ฒฐ์ ๋ฉ๋๋ค. (MariaDB ๋ฐ NGINX Uniy๋ฅผ ์คํํ๋ ๋ฐ ์ฌ์ฉ ๊ฐ๋ฅํ ๋ฉ๋ชจ๋ฆฌ)/(PHP์ RAM ์ ํ + 5)
์ด ๊ฐ์ NGINX ๋จ์ ์ค์ ์์ ์ค์ ๋ฉ๋๋ค.
๋ํ ์ด ๊ฐ์ ํญ์ ์ต์ ๋ ๊ฐ์ PHP ํ๋ก์ธ์ค๊ฐ ์คํ๋๊ณ ์์์ ์๋ฏธํฉ๋๋ค. ์ด๋ WordPress๊ฐ ์์ฒด์ ์ผ๋ก ๋ง์ ๋น๋๊ธฐ ์์ฒญ์ ํ๊ณ ์ถ๊ฐ ํ๋ก์ธ์ค๊ฐ ์คํ๋์ง ์์ผ๋ฉด 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
WordPress์ฉ NGINX ์ค์
๋ค์์ผ๋ก ์คํฌ๋ฆฝํธ๋ WordPress์ฉ ๊ตฌ์ฑ ํ์ผ์ ์์ฑํฉ๋๋ค. default.conf ์นดํ๋ก๊ทธ์ conf.d. ์ฌ๊ธฐ์์๋ ๋ค์๊ณผ ๊ฐ์ด ๊ตฌ์ฑ๋ฉ๋๋ค.
- Certbot์ ํตํด Let's Encrypt์์ ๋ฐ์ TLS ์ธ์ฆ์ ํ์ฑํ(๊ตฌ์ฑ์ ๋ค์ ์น์ ์์ ์งํ๋ฉ๋๋ค)
- Let's Encrypt์ ๊ถ์ฅ ์ฌํญ์ ๊ธฐ๋ฐ์ผ๋ก TLS ๋ณด์ ์ค์ ๊ตฌ์ฑ
- ๊ธฐ๋ณธ์ ์ผ๋ก ๊ฑด๋๋ด ์์ฒญ ์บ์ฑ์ 1์๊ฐ ๋์ ํ์ฑํํฉ๋๋ค.
- ์ผ๋ฐ์ ์ผ๋ก ์์ฒญ๋๋ ๋ ๊ฐ์ง ํ์ผ์ธ favicon.ico ๋ฐ robots.txt์ ๋ํด ์ก์ธ์ค ๋ก๊น ๊ณผ ํ์ผ์ ์ฐพ์ ์ ์๋ ๊ฒฝ์ฐ ์ค๋ฅ ๋ก๊น ์ ๋นํ์ฑํํฉ๋๋ค.
- ์จ๊ฒจ์ง ํ์ผ ๋ฐ ์ผ๋ถ ํ์ผ์ ๋ํ ์ก์ธ์ค ๊ฑฐ๋ถ . PHP๋๋ถ๋ฒ์ ์ธ ์ ์์ด๋ ์๋ํ์ง ์์ ์คํ์ ๋ฐฉ์งํ๊ธฐ ์ํด
- ์ ์ ๋ฐ ๊ธ๊ผด ํ์ผ์ ๋ํ ์ก์ธ์ค ๋ก๊น ๋นํ์ฑํ
- ์ ๋ชฉ ์ค์
์ก์ธ์ค ์ ์ด ํ์ฉ ์ถ์ฒ ๊ธ๊ผด ํ์ผ์ ๊ฒฝ์ฐ - 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
Let's Encrypt ์ธ์ฆ์๋ฅผ ์ํ Certbot ๊ตฌ์ฑ ๋ฐ ์๋ ๊ฐฑ์
- NGINX๋ฅผ ์ค์งํฉ๋๋ค.
- ๊ถ์ฅ TLS ์ค์ ๋ค์ด๋ก๋
- Certbot์ ์คํํ์ฌ ์ฌ์ดํธ์ ๋ํ ์ธ์ฆ์๋ฅผ ์ป์ต๋๋ค.
- ์ธ์ฆ์๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด NGINX๋ฅผ ๋ค์ ์์ํฉ๋๋ค.
- ๋งค์ผ ์ค์ 3์ 24๋ถ์ ์คํ๋๋๋ก Certbot์ ๊ตฌ์ฑํ์ฌ ์ธ์ฆ์๋ฅผ ์ ๋ฐ์ดํธํด์ผ ํ๋์ง ํ์ธํ๊ณ ํ์ํ ๊ฒฝ์ฐ ์ ์ธ์ฆ์๋ฅผ ๋ค์ด๋ก๋ํ๊ณ 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
์ฌ์ดํธ์ ์ถ๊ฐ ์ฌ์ฉ์ ์ ์
์ฐ๋ฆฌ๋ TLSSSL์ด ํ์ฑํ๋ ํ๋ก๋์ ์ง์ ์น์ฌ์ดํธ๋ฅผ ์ ๊ณตํ๊ธฐ ์ํด ์คํฌ๋ฆฝํธ๊ฐ NGINX ๋ฐ NGINX ์ ๋์ ๊ตฌ์ฑํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์์์ ์ด์ผ๊ธฐํ์ต๋๋ค. ํ์์ ๋ฐ๋ผ ๋์ค์ ๋ค์์ ์ถ๊ฐํ ์๋ ์์ต๋๋ค.
- ์ง์
๋ธ๋ก ํ๋ฆฌ , HTTPS๋ฅผ ํตํ ํฅ์๋ ์ค์๊ฐ ์์ถ ModSecurity๋ฅผ ัWordPress์ ๊ท์น ์ฌ์ดํธ์ ๋ํ ์๋ํ๋ ๊ณต๊ฒฉ์ ๋ฐฉ์งํ๊ธฐ ์ํด๋ฐฑ์ ๊ทํ์๊ฒ ์ ํฉํ WordPress์ฉ๋ณดํธ ๋ฅผ ํตํดAppArmor (์ฐ๋ถํฌ์์)- WordPress์์ ๋ฉ์ผ์ ๋ณด๋ผ ์ ์๋๋ก Postfix ๋๋ msmtp
- ์ฌ์ดํธ์์ ์ฒ๋ฆฌํ ์ ์๋ ํธ๋ํฝ ์์ ํ์ ํ๊ธฐ ์ํด ์ฌ์ดํธ๋ฅผ ํ์ธํฉ๋๋ค.
๋ ๋์ ์ฌ์ดํธ ์ฑ๋ฅ์ ์ํด์๋ ๋ค์์ผ๋ก ์
๊ทธ๋ ์ด๋ํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
NB ๋ก๋๊ฐ ๋ง์ ์น์ฌ์ดํธ์ ๋ํ ์ง์์ ๋ฐ์ผ๋ ค๋ฉด ์ ๋ฌธ๊ฐ์๊ฒ ๋ฌธ์ํ์ธ์.
์ฌ์ฐ์ค ๋ธ๋ฆฌ์ง . ์ฐ๋ฆฌ๋ ์ด๋ค ๋ถํ์์๋ ๊ทํ์ ์น์ฌ์ดํธ๋ ์๋น์ค๊ฐ ๋น ๋ฅด๊ณ ์์ ์ ์ผ๋ก ์๋ํ๋๋ก ๋ณด์ฅํ ๊ฒ์ ๋๋ค.
์ถ์ฒ : habr.com