Search
Duplicate
๐Ÿณ

ft_server

Holy Graph
2Circle
๊ฐ„๋žตํ•œ ๋‚ด์šฉ
Docker๋กœ WebServer ํ™˜๊ฒฝ ๊ตฌ์ถ•ํ•˜๊ธฐ
์ ์ • ๊ธฐ๊ฐ„
1 week
์ œ์ž‘์— ์ฐธ์—ฌํ•œ ์‚ฌ๋žŒ
์ง„ํ–‰ ์ค‘์ธ ์‚ฌ๋žŒ
์ตœ์ข… ํŽธ์ง‘์ผ
May 08
ํ†ต๊ณผํ•œ ์‚ฌ๋žŒ
1 more property
Tips
โ€ข
Guide comments
โ€ข
...

Subject

โ€ข
โ€ข
โ€ข
โ€ข
โ€ข

๋“ค์–ด๊ฐ€๊ธฐ ์•ž์„œ...

๋‚ด์šฉ์ด ๋งŽ์ด ๋ถ€์กฑํ•ด์„œ ์ถ”๊ฐ€ํ•  ๋ถ€๋ถ„, ์ˆ˜์ •์‚ฌํ•ญ ์žˆ์œผ๋ฉด ๋งŽ์ด ๋งŽ์ด ์†๋ด์ฃผ์„ธ์š”~~ Thanks
(์•ž ๋ถ€๋ถ„) Mac์—์„œ ์ž˜ ์•ˆ๋˜๋ฉด ์œ„ ๋งํฌ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š” !!

0. ft_server ๊ณผ์ œ ๋ชฉํ‘œ

1.
Docker์ด๋ฏธ์ง€๋กœย debian busterย ํ™˜๊ฒฝย ๋งŒ๋“ค๊ณ ย ์ ‘์†ํ•ด๋ณด๊ธฐ
2.
nginxย ์„ค์น˜ํ•˜๊ณ ย ๋กœ์ปฌํ˜ธ์ŠคํŠธ์—์„œย ์ ‘์†ํ•ด๋ณด๊ธฐ(docker portย ์„ค์ •)
3.
Nginx์—ย php์‹คํ–‰์‹œ์ผœย ๋„์›Œ๋ณด๊ธฐ(php์„ค์น˜ย ๋ฐย nginx confย ์„ค์ •)
4.
mysqlย ์‹คํ–‰ํ•ด๋ณด๊ธฐ(db๋ฅผย ํ•˜๋‚˜ย ๋งŒ๋“ค์–ด๋ณด๊ธฐ)
5.
phpmyadminย ์ ‘์†ํ• ์ˆ˜ย ์žˆ๊ฒŒย ์„ค์ •ํ•ด๋ณด๊ธฐ(์„ค์น˜ย ๋ฐย confย ์„ค์ •)
6.
wordpressย ์ ‘์†ํ• ์ˆ˜ย ์žˆ๊ฒŒย ์„ค์ •ํ•ด๋ณด๊ธฐ(์„ค์น˜ย ๋ฐย confย ์„ค์ •)
7.
wordpress์—ย db์ ์šฉ์‹œ์ผœ๋ณด๊ธฐ
8.
์œ„์˜ ๊ณผ์ •์„ย dockerfile๋กœย ์ž๋™ํ™”ย ์‹œํ‚ค๊ธฐ

1. Docker

Docs์—์„œ ๋งํ•˜๋Š” Docker๋Š” ํด๋ผ์šฐ๋“œ ๋˜๋Š” ์˜จ-ํ”„๋ ˆ๋ฏธ์Šค๋กœ ์‹คํ–‰๋  ์ˆ˜ ์žˆ๋Š” ์ด์‹ ๊ฐ€๋Šฅํ•˜๊ณ  ๋ฌธ์ œ๋ฅผ ์Šค์Šค๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ์ปจํ…Œ์ด๋„ˆ๋กœ์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐฐํฌ๋ฅผ ์ž๋™ํ™”ํ•˜๊ธฐ ์œ„ํ•œ ์˜คํ”ˆ ์†Œ์Šค ํ”„๋กœ์ ํŠธ์ž…๋‹ˆ๋‹ค. ๋ผ๊ณ  ์„ค๋ช…ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
์‰ฝ๊ฒŒ ๋งํ•˜๋ฉด ๋„์ปค๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ฐฐํฌ ๋ฐ ๊ณต์œ ํ•˜๋Š” ์˜คํ”ˆ ์†Œ์Šค ๊ฐ€์ƒํ™” ํ”Œ๋žซํผ์ž…๋‹ˆ๋‹ค.
๋‹ค์–‘ํ•œ ํ”„๋กœ๊ทธ๋žจ, ์‹คํ–‰ํ™˜๊ฒฝ์„ ์ปจํ…Œ์ด๋„ˆ๋กœ ์ถ”์ƒํ™”ํ•˜๊ณ  ๋™์ผํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•˜์—ฌ ํ”„๋กœ๊ทธ๋žจ์˜ ๋ฐฐํฌ ๋ฐ ๊ด€๋ฆฌ๋ฅผ ๋‹จ์ˆœํ•˜๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค.

1) ์ปจํ…Œ์ด๋„ˆ(container)

์ปจํ…Œ์ด๋„ˆ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋˜๋Š” ์„œ๋น„์Šค์™€ ๊ทธ์— ํ•ด๋‹นํ•˜๋Š” ๊ตฌ์„ฑ์ด ์ปจํ…Œ์ด๋„ˆ ์ด๋ฏธ์ง€๋กœ ํŒจํ‚ค์ง€๋˜๋Š” ์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.
์œ„์˜ ๊ทธ๋ฆผ์ฒ˜๋Ÿผ ๊ฐ ์ปจํ…Œ์ด๋„ˆ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋˜๋Š” ์„œ๋น„์Šค๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
VM์€ os๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ์–ด os๊ฐ€ ๋‘๊ฐœ๊ฐ€ ๋˜์ง€๋งŒ ์ปจํ…Œ์ด๋„ˆ๋Š”ย ์‹คํ–‰ํ•˜๋ ค๋Š” os์— Docker Engine์ด ์˜ฌ๋ผ๊ฐ€ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ตฌ์ถ•, ์‹œ์ž‘ ๋˜๋Š” ์ค‘๋‹จํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ„๋‹จํ•œ ๋ช…๋ น ์„ธํŠธ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
ํ•˜๋“œ์›จ์–ด๋ฅผ ๊ฐ€์ƒํ™”ํ•˜๊ณ  ์šด์˜์ฒด์ œ๋ฅผ ๊ฐ€์ƒํ™” ํ•˜๋Š” ๊ณณ ์ž์ฒด๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์— ๋ฉ”๋ชจ๋ฆฌ ์ ‘๊ทผ ์†๋„, ํŒŒ์ผ์‹œ์Šคํ…œ ์‚ฌ์šฉ ์†๋„, ๋„คํŠธ์›Œํฌ ์†๋„ ๋“ฑ์—์„œ VM์— ๋น„ํ•ด ์›”๋“ฑํžˆ ๋น ๋ฅธ ์†๋„๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค.

2) ๋„์ปค ์ด๋ฏธ์ง€(image)

Docker ์ด๋ฏธ์ง€๋Š” ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ •์˜ํ•˜๋Š” ์ฝ๊ธฐ ์ „์šฉ ํ…œํ”Œ๋ฆฟ์ž…๋‹ˆ๋‹ค. ์ด ์ด๋ฏธ์ง€์—๋Š” ์ฝ”๋“œ์— ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฐ ์ข…์†์„ฑ์— ๋Œ€ํ•œ ์ •์˜๋ฅผ ๋น„๋กฏํ•ด ์‹คํ–‰๋˜๋Š” ์ฝ”๋“œ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
Docker ์ปจํ…Œ์ด๋„ˆ๋Š” ์ธ์Šคํ„ด์Šคํ™”(์‹คํ–‰ํ•œ ์ƒํƒœ)๊ฐ€ ๋œ Docker ์ด๋ฏธ์ง€๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
๋„์ปค์ด๋ฏธ์ง€๋Š”ย hub.docker.com/์—์„œ ๋ฐฐํฌ ๋ฐ ๋‹ค์šด์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

3) Dockerfile

Search
NAME
Description
ex)
์‚ฌ์šฉํ•  ์ด๋ฏธ์ง€๋ฅผ ์ง€์ •ํ•˜๋Š” ๋ช…๋ น์–ด.ย :๋’ค์— ํŠน์ • ๋ฒ„์ „์„ ์ง€์ •ํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
FROMย ubuntu:18.04ย FROMย node
๋‚ด๋ ค๋ฐ›์€ ์ด๋ฏธ์ง€์— ์„ค์น˜ํ•  ํŒจํ‚ค์ง€ ๋˜๋Š” shell ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๋‹ค.
RUNย npmย installย -gย typescript:[version]
์‹คํ–‰ํ•œ container์™ธ๋ถ€์— ๋…ธ์ถœํ•  ํฌํŠธ๋ฅผ ์ง€์ •ํ•˜๋Š” ๋ช…๋ น์–ด
EXPOSEย 8080
ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์ง€์ •ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ํŒŒ์ผ๋‚ด๋ถ€์—์„œ ๋ณ€์ˆ˜์ฒ˜๋Ÿผ ํ™œ์šฉ์ด ๊ฐ€๋Šฅ
ENVย testย 123
cd์˜ ๋ช…๋ น์–ด์™€ ๋น„์Šทํ•ฉ๋‹ˆ๋‹ค. RUN๊ณผ CMD๊ณผ ๊ฐ™์€ ๋ช…๋ น์–ด๊ฐ€ ์‹คํ–‰๋  ์ด๋ฏธ์ง€ ๋‚ด๋ถ€์— ์œ„์น˜๋ฅผ ์ง€์ •ํ•ด์ฃผ๋Š” ๋ช…๋ น์–ด
WORKDIR /app/
๋นŒ๋“œ ์ค‘ ํ˜ธ์ŠคํŠธ์˜ ๋””๋ ‰ํ† ๋ฆฌ์—์„œ ํŒŒ์ผ์„ ๊ฐ€์ ธ์™€์„œ ์ด๋ฏธ์ง€์— ํŒŒ์ผ์„ ๋”ํ•˜๋Š” ๊ฒƒ.ย ย ๋นŒ๋“œ๋˜๋Š” ๋””๋ ‰ํ† ๋ฆฌ ๋ฐ–์— ์œ„์น˜ํ•˜๋Š” ํŒŒ์ผ๋“ค์€ ๊ฐ€์ ธ์˜ค์ง€ ์•Š๋Š”๋‹ค.
ADD test.txt /
์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ–ˆ์„๋•Œ ์‹คํ–‰ํ•  ๋ช…๋ น.ย ๋„์ปคํŒŒ์ผ์—์„œ ํ•œ๋ฒˆ๋งŒ ์‚ฌ์šฉ๊ฐ€๋Šฅ
ENTRYPOINTย ["npm",ย "run",ย "serve"]
docker run ์‹คํ–‰ ์‹œ ์‚ฌ์šฉํ•  default ๋ช…๋ น์„ ์„ค์ •
CMDย ["npm",ย "run",ย "serve"]
ํ˜ธ์ŠคํŠธ์˜ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ docker ์ปจํ…Œ์ด๋„ˆ์— ์—ฐ๊ฒฐํ•˜๋Š” ๋ช…๋ น์–ด
VOLUME ["/data", "/var/log"]
ํ•ด๋‹น docker ์ด๋ฏธ์ง€๋ฅผ ์‹คํ–‰ํ•  user๋ฅผ ์ง€์ •ํ•˜๋Š” ๋ช…๋ น์–ด
USERย userUSERย [uid]:[gid]
์ด๋ฏธ์ง€์— ๋ผ๋ฒจ์„ ๋‹ค๋Š” ๋ช…๋ น์–ด
LABELย "abcd@gmail.com"
๋„์ปคํŒŒ์ผ ๋นŒ๋“œ์‹œ์— ์„ค์ •ํ•˜๋Š” ์˜ต์…˜๋“ค์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๋ช…๋ น์–ด
ARGย arg1ARGย arg2=value

4) Docker ์ฃผ์š” ๋ช…๋ น์–ด

Docker build ๋ช…๋ น์–ด

docker build [OPTIONS] PATH | URL | -
Plain Text
๋ณต์‚ฌ
Search
options
description
-t [์ €์žฅ์†Œ ์ด๋ฆ„] / [์ด๋ฏธ์ง€ ์ด๋ฆ„] : [ํƒœ๊ทธ] ์„ค์ •

Docker ์‹คํ–‰ ๋ช…๋ น์–ด

docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
Plain Text
๋ณต์‚ฌ
Search
options
description
detached mode,ย ๋ณดํ†ต ๋ฐ๋ชฌ ๋ชจ๋“œ๋ผ๊ณ  ๋ถ€๋ฅด๋ฉฐ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋กœ ์‹คํ–‰
ํ˜ธ์ŠคํŠธ์™€ ์ปจํ…Œ์ด๋„ˆ์˜ ํฌํŠธ๋ฅผ ์—ฐ๊ฒฐ (ํฌ์›Œ๋”ฉ)
์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„ ์„ค์ •
์ปจํ…Œ์ด๋„ˆ ๋‚ด์—์„œ ์‚ฌ์šฉํ•  ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ •
ํ˜ธ์ŠคํŠธ์™€ ์ปจํ…Œ์ด๋„ˆ์˜ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์—ฐ๊ฒฐ(๋งˆ์šดํŠธ)
-i -t๋ฅผ ๋™์‹œ์— ์‚ฌ์šฉํ•œ๊ฒƒ์œผ๋กœย ํ‘œ์ค€ ์ž…๋ ฅ(stdin)์„ ํ™œ์„ฑํ™”,ย ํ„ฐ๋ฏธ๋„ ์ž…๋ ฅ์„ ์œ„ํ•œ ์˜ต์…˜
ํ”„๋กœ์„ธ์Šค ์ข…๋ฃŒ์‹œ ์ปจํ…Œ์ด๋„ˆ ์ž๋™ ์ œ๊ฑฐ
์ปจํ…Œ์ด๋„ˆ ์—ฐ๊ฒฐ [์ปจํ…Œ์ด๋„ˆ ๋ช… : ๋ณ„์นญ]

์ด๋ฏธ์ง€ ๋ชฉ๋ก ๋ณด๊ธฐ

$ docker images
Plain Text
๋ณต์‚ฌ

์ด๋ฏธ์ง€ ๊ฒ€์ƒ‰

$ docker search [์ด๋ฏธ์ง€ ์ด๋ฆ„]
Plain Text
๋ณต์‚ฌ

์ด๋ฏธ์ง€ ๋ฐ›๊ธฐ

$ docker pull [์ด๋ฏธ์ง€ ์ด๋ฆ„]:[๋ฒ„์ „]
Plain Text
๋ณต์‚ฌ
โ€ข
๋ฒ„์ „์„ย latestย ๋กœ ์“ฐ๋ฉด ์ตœ์‹  ๋ฒ„์ „์œผ๋กœ ๋ฐ›์„์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋ฏธ์ง€ ์‚ญ์ œ

$ docker rmi [์ด๋ฏธ์ง€ id]
Shell
๋ณต์‚ฌ
โ€ข
f ์˜ต์…˜์„ ๋ถ™ํžˆ๋ฉด ์ปจํ…Œ์ด๋„ˆ๋„ ๊ฐ•์ œ ์‚ญ์ œ๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก ๋ณด๊ธฐ

$ docker ps
Plain Text
๋ณต์‚ฌ
โ€ข
a ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ชจ๋“  ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

2. Debian buster

์šฐ๋ฆฌ์˜ ๊ณผ์ œ๋Š” ๋ฐ๋น„์•ˆ ๋ฒ„์Šคํ„ฐ๋ผ๋Š” os ์œ„์—์„œ ์‹คํ–‰์„ ์‹œ์ผœ์•ผ ํ•ฉ๋‹ˆ๋‹ค.
๋ฐ๋น„์•ˆ์€ OS ์ค‘ ํ•˜๋‚˜์ด๋ฉฐ 1993๋…„ 9์›” ์ฒซ ๋ฒ„์ „ ์ดํ›„ ์šฐ๋ถ„ํˆฌ๋ฅผ ๋น„๋กฏํ•œ ์ˆ˜๋งŽ์€ ๋ฆฌ๋ˆ…์Šค ๋ฐฐํฌํŒ์˜ ๋ชจ์ฒด๊ฐ€ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
ํ˜„์žฌ ์ตœ์‹  ์•ˆ์ • ๋ฒ„์ „์€ 2019๋…„ ๋ฐฐํฌ๋œ buster ์ž…๋‹ˆ๋‹ค.

ย debian buster ์ด๋ฏธ์ง€ ๋‹ค์šด

docker pull debian:buster
Plain Text
๋ณต์‚ฌ
docker run -it --name debian -p 80:80 -p 443:443 debian:buster
Plain Text
๋ณต์‚ฌ
โ€ข
p 80:80ย ํ˜ธ์ŠคํŠธ์˜ 80๋ฒˆ ํฌํŠธ๋ฅผ ์ปจํ…Œ์ด๋„ˆ์˜ 80๋ฒˆ ํฌํŠธ์™€ ์—ฐ๊ฒฐ (http ํ”„๋กœํ† ์ฝœ์˜ ๊ธฐ๋ณธ ํฌํŠธ๋Š” 80)
โ€ข
p 443:443 ํ˜ธ์ŠคํŠธ์˜ 443๋ฒˆ ํฌํŠธ๋ฅผ ์ปจํ…Œ์ด๋„ˆ์˜ 443ํฌํŠธ์™€ ์—ฐ๊ฒฐ (์ถ”ํ›„ ์ ์šฉ์‹œํ‚ฌ ssl์„ ์‚ฌ์šฉํ•  https์˜ ๊ธฐ๋ณธ ํฌํŠธ)

2. Nginx

nginx ๋Š” Apache๊ณผ ๊ฐ™์€ ์›น ์„œ๋ฒ„ ์†Œํ”„ํŠธ์›จ์–ด์ž…๋‹ˆ๋‹ค.

nginx ์„ค์น˜

apt-get update && apt-get -y install nginx
Plain Text
๋ณต์‚ฌ
โ€ข
๋„์ปคํŒŒ์ผ ๋‚ด์—์„œ๋Š” yes ๋ฅผ ๋ˆ„๋ฅผ์ˆ˜ ์—†์Œ์œผ๋กœ -y ํ”Œ๋ž˜๊ทธ๋ฅผ ๋ถ™์—ฌ์ค๋‹ˆ๋‹ค.

Nginx ๋ช…๋ น์–ด

service nginx start service nginx status service nginx reload
Plain Text
๋ณต์‚ฌ
nginx ๋ฅผ start ํ•œ ๋’ค localhost์— ๋“ค์–ด๊ฐ€ Welcome to nginx๊ฐ€ ๋œจ๋ฉด ์ •์ƒ ์ž‘๋™ ๋œ ๊ฒƒ ์ž…๋‹ˆ๋‹ค.

3. MariaDB(mySQL)

mySQL์€ ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ด€๋ฆฌ ์‹œ์Šคํ…œ์ž…๋‹ˆ๋‹ค. ์„œ๋ธŒ์ ํŠธ์—์„œ๋Š” mysql์„ ์š”๊ตฌํ•˜์ง€๋งŒ
๋ฐ๋น„์•ˆ ๋ฒ„์Šคํ„ฐ์—์„œ๋Š” mariaDB๋งŒ์„ ์ง€์›ํ•˜๊ธฐ ๋•Œ๋ฌธ์— mysql๊ณผ ์™„์ „ ํ˜ธํ™˜๋˜๋Š” mariaDB๋ฅผ ์„ค์น˜ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

MariaDB ์„ค์น˜

apt-get -y install mariadb-server # mysql ์‹คํ–‰ ๋ฐ ์„œ๋ฒ„ ์žฌ์‹คํ–‰ service mysql start service nginx reload
Plain Text
๋ณต์‚ฌ

mysql ๊ณ„์ • ๊ถŒํ•œ ์„ค์ •๊ณผ ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ์ƒ์„ฑ

# mysql ์‹คํ–‰ mysql; # wordpress ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑ CREATE DATABASE wordpress; # ์‚ฌ์šฉ์ž ๊ณ„์ • ์ƒ์„ฑ CREATE USER IF NOT EXISTS 'hyospark'@'localhost' IDENTIFIED BY 'hyospark'; # ๊ถŒํ•œ ์„ค์ • GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'localhost' WITH GRANT OPTION;
Plain Text
๋ณต์‚ฌ

4. PHP

1) PHP๋ž€?

server side script ๋กœ ์„œ๋ฒ„ ์ชฝ์—์„œ ๋™์ž‘ํ•˜๋Š” ์–ธ์–ด์ž…๋‹ˆ๋‹ค. php์™€ nginx๋ฅผ ์—ฐ๋™ํ•˜๊ธฐ ์œ„ํ•ด ์•Œ์•„์•ผ ํ•  ๋ช‡๊ฐ€์ง€ ๊ฐœ๋…๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค.
php ๊ฐ™์€ ๋‹ค์–‘ํ•œ ๋™์ ์ธ ํŒŒ์ผ์„ ๋ณด๋‚ด๊ธฐ ์œ„ํ•œ ๊ณผ์ •์—์„œ ๊ฐœ๋ฐœ๋œย CGI & FastCGI ํ‘œ์ค€์ด ์žˆ์Šต๋‹ˆ๋‹ค.

2) CGI(common gateway interface)

๊ณตํ†ต ๊ฒŒ์ดํŠธ์›จ์ด ์ธํ„ฐํŽ˜์ด์Šค์˜ ์•ฝ์–ด๋กœ, ์›น์„œ๋ฒ„์™€ ์™ธ๋ถ€ํ”„๋กœ๊ทธ๋žจ์„ ์—ฐ๊ฒฐํ•ด์ฃผ๋Š” ์ธํ„ฐํŽ˜์ด์Šค์ž…๋‹ˆ๋‹ค.
์•„๋ž˜ ์ด๋ฏธ์ง€๋ฅผ ๋ณด๋ฉด ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ๊ณ  ๋ฐ›์„๋•Œ์˜ CGI ๋™์ž‘ ๋ฐฉ์‹์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

3) FastCGI

๋Š๋ฆฐย CGI๋ฅผ ๊ฐœ์„ ํ•˜๊ธฐ ์œ„ํ•ด ๋“ฑ์žฅํ•œ ๊ฒƒ์œผ๋กœ CGI๋Š” ํ•˜๋‚˜์˜ ์š”์ฒญ์— ํ•˜๋‚˜์˜ ํ”„๋กœ์„ธ์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
ํ”„๋กœ์„ธ์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์‚ญ์ œํ•˜๋Š” ๊ณผ์ •์—์„œ ๋งŽ์€ ๋ถ€ํ•˜๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ ์†๋„๊ฐ€ ๋Š๋ ค์ง€๋Š” ๋‹จ์ ์ด ์žˆ์—ˆ๋Š”๋ฐ FastCGI๋Š” ๋งŒ๋“ค์–ด์ง„ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๊ณ„์†ํ•ด์„œ ์ƒˆ๋กœ์šด ์š”์ฒญ๋“ค์„ ์ฒ˜๋ฆฌํ•˜์—ฌ ๋ถ€ํ•˜๊ฐ€ ์ค„์–ด๋“ค๊ฒŒ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

4) PHP-FPM

PHP FastCGI Process Manager์˜ ์•ฝ์ž๋กœ PHP๋ฅผ FastCGI ๋ชจ๋“œ๋กœ ๋™์ž‘ํ•˜๋„๋ก ํ•ด์ค๋‹ˆ๋‹ค.
apt-get -y install php-fpm php-mysql php-mbstring curl wget vim
Plain Text
๋ณต์‚ฌ
vim /etc/nginx/sites-available/defaultย ํŒŒ์ผ์—์„œ php ๋ถ€๋ถ„ ์ฃผ์„์„ ํ•ด์ œํ•˜๊ณ  index๋ฅผ ์ถ”๊ฐ€ํ•ด ์ค๋‹ˆ๋‹ค.
index index.htm index.html index.php #index.nginx-debian.html; location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; }
Plain Text
๋ณต์‚ฌ

5. phpMyAdmin

phpMyAdmin์€ MySQL์„ ์›น ์ƒ์—์„œ ๊ด€๋ฆฌํ•  ๋ชฉ์ ์œผ๋กœ PHP๋กœ ์ž‘์„ฑํ•œ ์˜คํ”ˆ ์†Œ์Šค ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.
์ฆ‰ Mysql์„ ์›น์ƒ์—์„œ GUI๋กœ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ์˜คํ”ˆ์†Œ์Šค๋ฅผ php์–ธ์–ด๋กœ ๊ฐœ๋ฐœํ•œย MySQL Client ํˆด์ž…๋‹ˆ๋‹ค.
์•„๊นŒ ๋งŒ๋“  wordpress ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค๋ฅผ phpmyadmin์„ ํ†ตํ•ด ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ์—ฐ๊ฒฐ์„ ํ•ด์ฃผ๊ฒ ์Šต๋‹ˆ๋‹ค.

phpMyAdmin ์„ค์น˜

ํŒŒ์ผ ๋””๋ ‰ํ† ๋ฆฌ ์ƒ์„ฑ๊ณผ ํŒŒ์ผ ์ด๋™
wget https://files.phpmyadmin.net/phpMyAdmin/5.0.2/phpMyAdmin-5.0.2-all-languages.tar.gz tar -xvf phpMyAdmin-5.0.2-all-languages.tar.gz mv phpMyAdmin-5.0.2-all-languages phpmyadmin mv phpmyadmin /var/www/html/
Plain Text
๋ณต์‚ฌ

6. WordPress

ํ™ˆํŽ˜์ด์ง€ ์ œ์ž‘์„ ํ•  ์ˆ˜ ์žˆ๋Š” ์›น์‚ฌ์ดํŠธ

wordpress ์„ค์น˜

wget https://wordpress.org/latest.tar.gz tar -xvf latest.tar.gz mv wordpress/ var/www/html/ chown -R www-data:www-data /var/www/html/wordpress cp var/www/html/wordpress/wp-config-sample.php var/www/html/wordpress/wp-config.php
Plain Text
๋ณต์‚ฌ
vim var/www/html/wordpress/wp-config.php ํŒŒ์ผ์—์„œ ์•„๊นŒ ์ƒ์„ฑํ•œ ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ๋ช…๊ณผ ์œ ์ € ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ์ˆ˜์ •ํ•ด์ค๋‹ˆ๋‹ค.

7. SSL protocol

SSL(Secureย Socketย Layer)๋Š” ๋ณด์•ˆ๊ณ„์ธต ํ”„๋กœํ† ์ฝœ ์ž…๋‹ˆ๋‹ค.
์‘์šฉ๊ณ„์ธต๊ณผ ์ „์†ก ๊ณ„์ธต ์‚ฌ์ด์— ์†ํ•˜๋Š” ํ”„๋กœํ† ์ฝœ๋กœ SSL ์œ„์— ์‘์šฉ ํ”„๋กœํ† ์ฝœ์ด ์˜ฌ๋ผ๊ฐ€๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ฆ‰ HTTP ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋‹ค๋ฅธ ํ”„๋กœํ† ์ฝœ์—๋„ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
handshake ๋‚˜ cipher ๊ฐ™์€ ํ”„๋กœํ† ์ฝœ์€ ์ด๊ณณ์—์„œ๋Š” ์ƒ๋žตํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
HTTPS(HyperTextย Transferย Protocol overย Secure Socket Layer) ๋Š” http์˜ ๋ณด์•ˆ์ด ๊ฐ•ํ™”๋œ ๋ฒ„์ „์œผ๋กœย SSH์™€ HTTP๊ฐ€ ๊ฒฐํ•ฉ๋œ ๊ฒƒ์„ ์˜๋ฏธํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.ย ์œ„์— ๋งํ–ˆ๋“ฏ์ด HTTPS์˜ ๊ธฐ๋ณธ TCP/IP ํฌํŠธ๋Š” 443์ž…๋‹ˆ๋‹ค.
https๋Š” ์†Œ์ผ“ํ†ต์‹ ์—์„œ ์ผ๋ฐ˜ ํ…์ŠคํŠธ๋ฅผ ์ด์šฉํ•˜๋Š” ๋Œ€์‹ ์— SSL / TLS ํ”„๋กœํ† ์ฝœ์„ ํ†ตํ•ด ์„ธ์…˜ ๋ฐ์ดํ„ฐ๋ฅผ ์•”ํ˜ธํ™”ํ•ฉ๋‹ˆ๋‹ค.

๋Œ€์นญํ‚ค

๋Œ€์นญํ‚ค๋Š” ์•”ํ˜ธํ™” ํ•  ์ˆ˜ ์žˆ๋Š” ํ‚ค๋ฅผ ๊ฐ€์ง€๊ณ  ๊ทธ ํ‚ค๋กœ ๋ณตํ˜ธํ™”๋„ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. ๋Œ€์นญํ‚ค๋Š” ๊ณต๊ฐœํ‚ค ๋ฐฉ์‹์— ๋น„ํ•ด ๋น ๋ฅด๋‹ค๋Š” ์žฅ์ ์ด ์žˆ์ง€๋งŒ ๋Œ€์นญํ‚ค์˜ ํ•œ๊ณ„๋Š” ํ‚ค๋ฅผ ์ „์†กํ• ๋•Œ ์•ˆ์ „ํ•˜์ง€ ์•Š๋‹ค๋Š” ๊ฒƒ๊ณผ ์ „๋ถ€ ํ‚ค๋ฅผ ๋”ฐ๋กœ ํ‚ค๊ตํ™˜์„ ํ•ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ด€๋ฆฌํ•ด์•ผ ํ•  ํ‚ค๊ฐ€ ๋งŽ์•„์ง„๋‹ค๋Š” ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๊ณต๊ฐœํ‚ค

๋Œ€์นญํ‚ค์˜ ํ‚ค๊ตํ™˜ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๋‚˜์˜จ ๊ณต๊ฐœํ‚ค ๋ฐฉ์‹์€ ๋‘๊ฐœ์˜ ํ‚ค๋ฅผ ๊ฐ€์ง€๊ณ  ํ•˜๋‚˜๋Š” ๋น„๊ณต๊ฐœํ‚ค(private key)๋ผ ๋ถ€๋ฅด๊ณ  ๋‚˜๋จธ์ง€๋ฅผ ๊ณต๊ฐœํ‚ค(public key)๋กœ ์ง€์ •ํ•ด ํ•˜๋‚˜์˜ ํ‚ค๊ฐ€ ๋ณตํ˜ธํ™” ํ˜น์€ ์•”ํ˜ธํ™”๋งŒ ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ง€์ •ํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.
์šฐ๋ฆฌ๋Š”ย ๋ฌด๋ฃŒ ์˜คํ”ˆ์†Œ์Šค์ธย opensslย ์„ ์ด์šฉํ•ด ํ‚ค๋ฅผ ๋ฐœ๊ธ‰ ๋ฐ›์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

openssl ์„ค์น˜ํ•˜๊ธฐ

apt-get -y install openssl
Plain Text
๋ณต์‚ฌ
๊ฐœ์ธ ํ‚ค (.key) ์™€ ์ธ์ฆ์„œ ์„œ๋ช… ์š”์ฒญ ํŒŒ์ผ (.csr)์„ ์ƒ์„ฑํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
rsa: ๋Š” ํ‚ค์˜ ํฌ๊ธฐ๋กœ ๋ณด์•ˆ์˜ ์ •๋„๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๊ณ  -days๋Š” ์ธ์ฆ์„œ์˜ ์œ ํšจ๊ธฐ๊ฐ„์„ย -nodes๋Š”ย ๊ฐœ์ธํ‚ค๋ฅผ ์•”ํ˜ธํ™”ํ•˜์ง€ ์•Š์Œ์„ย ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

๊ฐœ์ธํ‚ค ๋ฐ ์ธ์ฆ์„œ ์ƒ์„ฑ

mkdir /etc/nginx/ssl openssl req -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=KR/ST=Seoul/L=Seoul/O=42Seoul/OU=Lee/CN=localhost" -keyout /etc/nginx/ssl/localhost.key -out /etc/nginx/ssl/localhost.crt chmod 600 /etc/nginx/ssl/localhost.crt /etc/nginx/ssl/localhost.key
Plain Text
๋ณต์‚ฌ
vim /etc/nginx/sites-available/default ํŒŒ์ผ์— ssl ์„ ํ™œ์„ฑํ™” ์‹œ์ผœ์ฃผ๊ณ  443ํฌํŠธ์™€ ๋ฆฌ๋‹ค์ด๋ ‰์…˜์„ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค.
server { listen 80; listen [::]:80; return 301 https://$host$request_uri; } server { listen 443 ssl; listen [::]:443 ssl; # ssl setting ssl on; ssl_certificate /etc/nginx/ssl/localhost.crt; ssl_certificate_key /etc/nginx/ssl/localhost.key; # ์„œ๋ฒ„ ๋ฃจํŠธ ๊ฒฝ๋กœ ์ง€์ • root /var/www/html; index index.htm index.html index.php index.nginx-debian.html; server_name ft_server; location / { try_files $uri $uri/ =404; } # PHP ์ถ”๊ฐ€ location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; } }
Plain Text
๋ณต์‚ฌ
์ƒ์„ฑ ํ›„์—๋Š” ํ•œ๋ฒˆ nginx๋ฅผ ์žฌ์‹คํ–‰ ํ•ด์ค๋‹ˆ๋‹ค.
service nginx reload
Plain Text
๋ณต์‚ฌ
๋‹ค์‹œ localhost ๋กœ ๋“ค์–ด๊ฐ”์„ ๋•Œ ํ•ด๋‹น ๊ฒฝ๊ณ ์ฐฝ์ด ๋œจ๊ณ  ๊ณ ๊ธ‰ -> localhost ๋“ค์–ด๊ฐ€๋ฉด ssl ์ ์šฉ์ด ์™„๋ฃŒ๋œ ๊ฒƒ์ด๋‹ค.

8. autoindex

์˜คํ† ์ธ๋ฑ์Šค๋Š” root ๋””๋ ‰ํ† ๋ฆฌ์— ์žˆ๋Š” ํŒŒ์ผ๋“ค์„ ๋ฆฌ์ŠคํŠธ๋กœ ๋ณด์—ฌ์ฃผ๋Š” ๊ธฐ๋Šฅ
vim etc/nginx/sites-available/default ์— ํ•ด๋‹น ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•˜๊ณ ย ย index.nginx-debian.html ๋ฅผ ์ฃผ์„ ์ฒ˜๋ฆฌํ•ด์ค๋‹ˆ๋‹ค.
location / { autoindex on; try_files $uri $uri/ =404; }
Plain Text
๋ณต์‚ฌ
localhost ์ ‘์†ํ•˜๋ฉด ๋ฆฌ์ŠคํŠธ๊ฐ€ ๋‚˜์˜ค๋Š” ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด์ œ ์œ„์˜ ๊ณผ์ •์„ ๋„์ปคํŒŒ์ผ๋กœ ์ž๋™ํ™”์‹œ์ผœ๋ด…์‹œ๋‹ค.