๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Study

[NGINX] NGINX๋ž€? NGINX ์„ค์น˜

by JulesJ 2022. 4. 13.
728x90

 

Nginx๋ž€?

 

NginX๋ž€?

์›น ์„œ๋ฒ„ ์†Œํ”„ํŠธ์›จ์–ด๋กœ, ๊ฐ€๋ฒผ์›€๊ณผ ๋†’์€ ์„ฑ๋Šฅ์„ ๋ชฉํ‘œ๋กœ ํ•œ๋‹ค. ์›น ์„œ๋ฒ„, ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ ๋ฐ ๋ฉ”์ผ ํ”„๋ก์‹œ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง„๋‹ค.
Nginx๋Š” ์š”์ฒญ์— ์‘๋‹ตํ•˜๊ธฐ ์œ„ํ•ด ๋น„๋™๊ธฐ ์ด๋ฒคํŠธ ๊ธฐ๋ฐ˜ ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง€๋ฉฐ, ์ด๋Š” ์•„ํŒŒ์น˜ HTTP ์„œ๋ฒ„์˜ ์Šค๋ ˆ๋“œ/ํ”„๋กœ์„ธ์Šค ๊ธฐ๋ฐ˜ ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง€๋Š” ๊ฒƒ๊ณผ๋Š” ๋Œ€์กฐ์ ์ด๋‹ค. ์ด๋Ÿฌํ•œ ๊ตฌ์กฐ๋Š” ์„œ๋ฒ„์— ๋งŽ์€ ๋ถ€ํ•˜๊ฐ€ ์ƒ๊ธธ ๊ฒฝ์šฐ์˜ ์„ฑ๋Šฅ์„ ์˜ˆ์ธกํ•˜๊ธฐ ์‰ฝ๊ฒŒ ํ•ด์ค€๋‹ค.

์ถœ์ฒ˜: [์œ„ํ‚ค๋ฐฑ๊ณผ]

 

๊ฐ„๋‹จํ•˜๊ฒŒ ๋งํ•˜๋ฉด ๊ฒฝ๋Ÿ‰ ์›น ์„œ๋ฒ„์ด๋ฉฐ, ํด๋ผ์ด์–ธํŠธ๋กœ๋ถ€ํ„ฐ ์š”์ฒญ์„ ๋ฐ›์•˜์„ ๋•Œ ์š”์ฒญ์— ๋งž๋Š” ์ •์  ํŒŒ์ผ์„ ์‘๋‹ตํ•ด์ฃผ๋Š” HTTP Web Server๋กœ ํ™œ์šฉ๋˜๊ธฐ๋„ ํ•˜๊ณ , Reverse Proxy Server๋กœ ํ™œ์šฉํ•˜์—ฌ WAS ์„œ๋ฒ„์˜ ๋ถ€ํ•˜๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ๋Š” ๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ๋กœ ํ™œ์šฉ๋˜๊ธฐ๋„ ํ•œ๋‹ค.

 

๋ณธ์ธ์€ React๋ฅผ Nginx๋กœ ๋ฐฐํฌํ•˜๊ธฐ์ „ ๊ฐ„๋‹จํžˆ Nginx์˜ ๊ฐœ๋…์„ ์ •๋ฆฌํ•ด๋ณด๊ณ , ์„ค์น˜๋ฅผ ์‹œ์ž‘ํ–ˆ๋‹ค.

 

๊ฐœ๋ฐœํ™˜๊ฒฝ: MacOS (m1)

 

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

 

์•„๋ž˜ ๋ฐฉ๋ฒ•์œผ๋กœ NGINX๋ฅผ ์„ค์น˜ํ•˜๊ธฐ ์ „ brew ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.

 

๋ณธ์ธ์€ ์ด๋ฏธ brew๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ์–ด ๋ฒ„์ „ ํ™•์ธ์œผ๋กœ ํ™•์ธ๋งŒ ํ•˜๊ณ  nginx ์„ค์น˜๋ฅผ ์‹œ์ž‘ํ–ˆ๋‹ค.

brew๋ฅผ ์ด์šฉํ•ด nginx๋ฅผ ์„ค์น˜ํ•˜๊ธฐ ๋•Œ๋ฌธ์— brew๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค๋ฉด, ๋ฏธ๋ฆฌ ์„ค์น˜ํ•˜๊ณ  ์ง„ํ–‰ํ•˜๋ฉด ๋  ๊ฒƒ์ด๋‹ค.

 

  • Homebrew ๋ฒ„์ „ ํ™•์ธ
brew -v

 

  • nginx ์„ค์น˜ํ•˜๊ธฐ
brew install nginx

→ brew๋ฅผ ์ด์šฉํ•ด NginX๋ฅผ ์„ค์น˜ํ•œ๋‹ค.

 

 

nginx.conf ํŒŒ์ผ ๊ฒฝ๋กœ ํ™•์ธํ•˜๊ธฐ

 

brew info nginx

→ brew info ${package๋ช…}: ํ•ด๋‹น ํŒจํ‚ค์ง€๊ฐ€ ์–ด๋Š ์œ„์น˜์— ์„ค์น˜๋˜์–ด ์žˆ๋Š” ์ง€ ํ™•์ธ ๊ฐ€๋Šฅํ•˜๋‹ค.

 

์„ค์น˜๋˜์–ด ์žˆ๋Š” ๊ฒฝ์šฐ ์•„๋ž˜์™€ ๊ฐ™์ด ์ •๋ณด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. 

nginx: stable 1.21.6, HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
<https://nginx.org/>
/opt/homebrew/Cellar/nginx/1.21.6_1 (26 files, 2.2MB) *
  Poured from bottle on 2022-04-13 at 14:30:40
From: <https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/nginx.rb>
License: BSD-2-Clause
==> Dependencies
Required: openssl@1.1 โœ”, pcre2 โœ”
==> Options
--HEAD
        Install HEAD version
==> Caveats
Docroot is: /opt/homebrew/var/www

The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /opt/homebrew/etc/nginx/servers/.

To restart nginx after an upgrade:
  brew services restart nginx
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/nginx/bin/nginx -g daemon off;
==> Analytics
install: 39,803 (30 days), 123,899 (90 days), 485,441 (365 days)
install-on-request: 39,713 (30 days), 123,684 (90 days), 484,435 (365 days)
build-error: 24 (30 days)

 

๋งฅ ๋ฒ„์ „์ด๋‚˜ ์ƒํ™ฉ์— ๋”ฐ๋ผ ์„ค์น˜ ์œ„์น˜๊ฐ€ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์œผ๋‹ˆ, ์Šค์Šค๋กœ ํ™•์ธํ•ด๋ณด๋Š” ๊ฒƒ์ด ์ œ์ผ ์ •ํ™•ํ•˜๋‹ค.

 

๋ณธ์ธ์˜ ๊ฒฝ์šฐ์—๋Š”

/opt/homebrew/etc/nginx/nginx.conf

์— conf ํŒŒ์ผ์ด ์œ„์น˜ํ•ด ์žˆ๋‹ค.

 

 

nginx.conf ํŒŒ์ผ ์ˆ˜์ •

 

์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด nginx.conf ํŒŒ์ผ์„ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

(password๋ฅผ ์š”๊ตฌํ•˜๋Š” ๊ฒฝ์šฐ ์ปดํ“จํ„ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค.)

sudo vim /opt/homebrew/etc/nginx/nginx.conf

 

nginx.conf ํŒŒ์ผ์„ ํ™•์ธ ํ•˜๋ฉด server ๋ถ€๋ถ„์ด ์„ค์ •๋˜์–ด ์žˆ๋‹ค.

server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

 

  • ๊ธฐ๋ณธ ํฌํŠธ๋ฅผ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด
listen 80; 

์œ„์™€ ๊ฐ™์ด ์›ํ•˜๋Š” ํฌํŠธ๋กœ ์ˆ˜์ •์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

 

  • root html์€ ์›น ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ์˜ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ์ด๋ฉฐ ๊ฐœ์ธ์šฉ์œผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๋ฃจํŠธ ๋””๋ ‰ํ„ฐ๋ฆฌ ์„ค์ •์„ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ๊ทธ๋Œ€๋กœ ๊ฐ€์ ธ์™€์„œ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์ด์šฉํ•œ๋‹ค.
# ์ ‘๊ทผํ•˜๊ธฐ ์‰ฝ๊ณ , ์›ํ•˜๋Š” ๋””๋ ‰ํ† ๋ฆฌ์—์„œ ์‹ฌ๋ณผ๋ฆญ ๋งํฌ๋ฅผ ์ƒ์„ฑ.
ln -s /opt/homebrew/var/www [๋งํฌ ์ด๋ฆ„]

 

Homebrew๋กœ ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์„œ๋น„์Šค ๊ด€๋ฆฌ

brew services # ์ž๋™์œผ๋กœ homebrew/services๋ฅผ tap, ํ˜„์žฌ ์„ค์น˜๋œ ์„œ๋น„์Šค ๋ชฉ๋ก ํ™•์ธ
brew services [run|start|stop|restart|cleanup] service_name # ๋ช…๋ น์–ด
# run - ์‹œ์ž‘ํ•˜๋˜, ์‹œ์ž‘ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ๋“ฑ๋กํ•˜์ง€ ์•Š์Œ
# start - ์‹œ์ž‘ํ•˜๊ณ  ์‹œ์ž‘ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ๋“ฑ๋ก

brew services start nginx # nginx ์‹œ์ž‘

homebrew services๋ฅผ ์ด์šฉํ•˜๋ฉด ์‰ฝ๊ฒŒ ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์„œ๋น„์Šค๋ฅผ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.

conf ํŒŒ์ผ ์ˆ˜์ •์„ ์™„๋ฃŒํ•œ๋‹ค๋ฉด ์•„๋ž˜ ๋ช…๋ น์–ด๋กœ nginx๋ฅผ ์žฌ์‹œ์ž‘ ํ•  ์ˆ˜ ์žˆ๋‹ค.

brew service restart nginx

 

NGINX ๋ช…๋ น์–ด

# ์‹œ์ž‘
nginx

# ์ค‘์ง€
nginx -s stop

# ์žฌ์‹œ์ž‘
nginx -s reload

 

Reference

https://ko.wikipedia.org/wiki/Nginx

https://icarus8050.tistory.com/57

 

[Nginx] Nginx ์ดํ•ดํ•˜๊ธฐ

Nginx?  Nginx๋Š” ๊ฐ„๋‹จํ•˜๊ฒŒ ๋ง์”€๋“œ๋ฆฌ์ž๋ฉด ๊ฒฝ๋Ÿ‰ ์›น ์„œ๋ฒ„์ž…๋‹ˆ๋‹ค. ํด๋ผ์ด์–ธํŠธ๋กœ๋ถ€ํ„ฐ ์š”์ฒญ์„ ๋ฐ›์•˜์„ ๋•Œ ์š”์ฒญ์— ๋งž๋Š” ์ •์  ํŒŒ์ผ์„ ์‘๋‹ตํ•ด์ฃผ๋Š” HTTP Web Server๋กœ ํ™œ์šฉ๋˜๊ธฐ๋„ ํ•˜๊ณ , Reverse Proxy Server๋กœ ํ™œ์šฉํ•˜์—ฌ

icarus8050.tistory.com

https://jehwanyoo.net/2021/04/06/mac-NGINX-Tutorial-1-NGINX-์„ค์น˜/

 

(mac) NGINX Tutorial #1 - NGINX ์„ค์น˜

ํ•ด๋‹น ํŠœํ† ๋ฆฌ์–ผ๋ฅผ ์‹œ์ž‘ํ•˜๊ธฐ ์ „์— brew ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ด์ฃผ์„ธ์š”! (๋งํฌ) NGINX ์„ค์น˜ํ•˜๊ธฐ1brew install nginx brew๋ฅผ ์ด์šฉํ•ด NginX๋ฅผ ์„ค์น˜ํ•ด์ค๋‹ˆ๋‹ค. nginx.conf ํŒŒ์ผ ๊ฒฝ๋กœ ํ™•์ธ1brew info nginx

jehwanyoo.net

์ฐธ๊ณ  ์ผ์ž (2022.04.13)

๋Œ“๊ธ€