1. ๋ฌธ์ ์ํฉ
ํด๋ผ์ฐ๋ ํ๋ซํผ์ ์ฌ์ฉํ ์ ์๊ณ ํ๊ต ์๋ฒ์ค ๋ฌผ๋ฆฌ ์ปดํจํฐ(Ubuntu 20.04)์ ๋ฐฐํฌํด์ผ ํ๋ ์ํฉ์ด๋ค.
๋ฌผ๋ฆฌ ์ปดํจํฐ๋ ๋จ 1๋๋ง ์ฌ์ฉํ ์ ์์ด์ ๋ชจ๋ ์ฒ๋ฆฌ๋ฅผ ํ ๊ณณ์์ ํด์ผํ๋ค.
์ด๋ฌํ ์ํฉ์์ Nginx ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด์.
2. ๋ฌธ์ ํด๊ฒฐ
์ฐ์ ํ์ฌ Nginx๋ Docker ์ปจํ
์ด๋์์์ ๋์ํ๊ณ ์์ผ๋ฏ๋ก
Nginx ์ปจํ
์ด๋์์ /usr/share/html/html ๊ฒฝ๋ก์ ๋ด ๋ฌผ๋ฆฌ์๋ฒ์ React App์ Buildํ ๊ฒฐ๊ณผ๋ฌผ ํด๋์ ๊ฒฝ๋ก๋ฅผ ๋ณผ๋ฅจ ๋งคํํ๋ ๊ณผ์ ์ด ๋จผ์ ํ์ํ๋ค.
๋ํ Nginx ์ปจํ
์ด๋์ ๊ฐ์ ๋คํธ์ํฌ ์์ kiosek-backend ์ด๋ฆ์ ์คํ๋๊ณ ์๋ ์ปจํ
์ด๋๊ฐ ์๋ค๊ณ ๊ฐ์ ํ๋ค.
1. ์ฌ์ฉ์๊ฐ ๋ธ๋ผ์ฐ์ ์์ http://test.kr ์ ์ ๋ ฅํ์ฌ ๋์ Nginx Web Server์ ์์ฒญ์ ํ๋ฉด build ๊ฒฐ๊ณผ๋ฌผ ์ค์ ํ๋์ธ index.html Document๋ฅผ ๋ธ๋ผ์ฐ์ ๋ก ์ ์กํ๋ค.
2. ๋ธ๋ผ์ฐ์ ์์๋ index.html ๋ด๋ถ์ Script๊ฐ ๋์ํ์ฌ js ํ์ผ์ ์คํํ์ฌ jsํ์ผ ๋ด๋ถ์ api ํธ์ถํ๋ ์คํฌ๋ฆฝํธ๊ฐ ๋์ํ์ฌ http://test.kr/api/v1/reservations ์ ๊ฐ์ API ์์ฒญ์ด ๋ค์ Nginx๋ก ๋ค์ด์ค๊ฒ ๋๋ค.
3. ์ด๋๋ Spring Tomcat Server๋ก ์์ฒญ์ Proxy Passํด์ค์ผ ํ๋ค.
๊ฐ๋จํ๊ฒ ์์ ๊ฐ์ ์์๋ก ๋์ํ๋ค.
โ๏ธ ์ค์ https://kiosek.kr์ ๋ธ๋ผ์ฐ์ ์ ์ ๋ ฅํ์๋ ํ์ธ ๊ฐ๋ฅํ Network Traffic
kiosek.kr์ ์์ฒญ์ Response๋ก index.html์ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์์จ๊ฒ์ ์ ์ ์๋ค. ๊ทธ ๋ค๋ก๋ js, css, imgํ์ผ๋ฑ์ด ์คํ ๋ฐ ๋ ๋๋ง๋๊ณ
๋ง์ง๋ง์นธ์ reservations?....๋ผ๋ ํธ์ถ์ด ๋ฐ์ํ๊ฒ์ ๋ณผ ์ ์๋๋ฐ ์ด์ Reuest URL์ ํ์ธํด๋ณด๋ฉด https://kiosek.kr/api/v1/reservations?... ์ ํธ์ถ์ด ๋ฐ์ํ์ฌ Response ๊ฐ์ WAS -> Web Server๋ฅผ ํตํด ๋ฐ์์ค๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
โ๏ธ nginx.conf ํ์ผ
์๋๋ ์์์ ์ค๋ช ํ ๊ฒ์ ๊ทธ๋๋ก ์ค์ ํด๋์ ์ค์ ํ์ผ ์์์ด๋ค.
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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;
keepalive_timeout 65;
upstream kiosek-backend {
server <WAS ์ฃผ์>
}
server {
listen 80;
listen [::]:80;
server_name www.test.kr www.test.kr;
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://kiosek-backend;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}