IaC Application

3tier Web Server Http -> Nginx ๊ตฌํ˜„

NENGIN 2024. 4. 17. 12:50

3 Tier Architecture๋ž€

ํ•œ ํ”Œ๋žซํผ์„ 3๊ณ„์ธต์œผ๋กœ ๋‚˜๋ˆ„์–ด ๋ณ„๋„์˜ ๋…ผ๋ฆฌ์ /๋ฌผ๋ฆฌ์ ์ธ ์žฅ์น˜์— ๊ตฌ์ถ• ๋ฐ ์šด์˜ํ•˜๋Š” ํ˜•ํƒœ์ด๋‹ค.

์„œ๋ฒ„ ํ•œ ๋Œ€์— ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ๊ตฌ์ถ•ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๊ณ  ์ฝ๋Š” ๋ฐ์ดํ„ฐ ๊ณ„์ธต,

๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ณ„์ธต, ๊ทธ๋ฆฌ๊ณ  ๋ฐ์ดํ„ฐ๋ฅผ ํ‘œํ˜„ํ•ด์ฃผ๋Š” ํด๋ผ์ด์–ธํŠธ(ํ”„๋ ˆ์  ํ…Œ์ด์…˜) ๊ณ„์ธต๊ณผ ๊ฐ™์ด

๊ฐ๊ฐ 3๊ณ„์ธต์œผ๋กœ ๋‚˜๋ˆ„์–ด ๊ฐ๊ฐ์˜ ๊ธฐ๋Šฅ์œผ๋กœ ๋ณ„๋„์˜ ๋…ผ๋ฆฌ์ /๋ฌผ๋ฆฌ์ ์ธ ์žฅ์น˜์—์„œ ์šด์˜ํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค.

WEB, WAS, DB ์„œ๋ฒ„๋ฅผ ๋ฌผ๋ฆฌ์ ์œผ๋กœ ๋‚˜๋ˆ„์–ด ๊ตฌ์„ฑํ•˜๊ณ  ๊ฐ๊ฐ์˜ ์„œ๋ฒ„์—์„œ ๋ณ€ํ™”๊ฐ€ ์ผ์–ด๋‚˜๋”๋ผ๋„ ์„œ๋กœ ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š๊ณ ๋…๋ฆฝ์ ์œผ๋กœ ์šด์˜๋œ๋‹ค.

 

 

 

โ— ๊ธฐ์กด 3tier ๊ตฌ์„ฑ๋„(๋ชจ๋“  ์„œ๋ฒ„ rocky9 ๊ธฐ์ค€)

๊ธฐ์กด ๊ตฌ์„ฑํ–ˆ๋˜ 3tier๋Š” httpd ์„œ๋ฒ„/php-fpm ์„œ๋ฒ„/OracleDB๋กœ ์‹คํ–‰๋œ๋‹ค

 

โ— HTTP server -> NGINX server ๊ตฌ์„ฑ๋„

Web ์„œ๋ฒ„ httpd๋ฅผ nginx๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ๊ธฐ์กด 3tier ์›นํŽ˜์ด์ง€์™€ ๋™์ผํ•˜๊ฒŒ ๊ตฌ์„ฑํ•ด์•ผ ํ•œ๋‹ค.

 

 

 

1. nginx ์„œ๋น„์Šค ์„ค์น˜

[root@WEB ~]# dnf -y install nginx

 

 

 

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

[root@WEB ~]# ls /etc/nginx/nginx.conf

// confํŒŒ์ผ ์Šคํฌ๋ฆฝํŠธ
 17 http {
 18     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 19                       '$status $body_bytes_sent "$http_referer" '
 20                       '"$http_user_agent" "$http_x_forwarded_for"';
 21
 22     access_log  /var/log/nginx/access.log  main;
 23
 24     sendfile            on;
 25     tcp_nopush          on;
 26     tcp_nodelay         on;
 27     keepalive_timeout   65;
 28     types_hash_max_size 4096;
 29
 30     include             /etc/nginx/mime.types;
 31     default_type        application/octet-stream;
 32
 33     # Load modular configuration files from the /etc/nginx/conf.d directory.
 34     # See http://nginx.org/en/docs/ngx_core_module.html#include
 35     # for more information.
 36     include /etc/nginx/conf.d/*.conf;
 37
 38     server {
 39         listen       80;
 40         listen       [::]:80;
 41         server_name  _;
 42         root         /usr/share/nginx/html;
 43
 44         # Load configuration files for the default server block.
 45         include /etc/nginx/default.d/*.conf;
 46
 47         error_page 404 /404.html;
 48         location = /404.html {
 49         }
 50
 51         error_page 500 502 503 504 /50x.html;
 52         location = /50x.html {
 53         }
 54
 55         location ~ \.php$ {
 56             #root           html;
 57             root           /usr/share/nginx/html;
 58             fastcgi_pass   192.168.101.51:9000;
 59             fastcgi_index  index.php;
 60             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 61             include        fastcgi_params;
 62         } // php ๋ธ”๋Ÿญ๋ถ€๋ถ„์„ ์ถ”๊ฐ€ํ•˜๊ธฐ, was server ip/port/๊ฒฝ๋กœ ์ง€์ • ํ™•์‹คํ•˜๊ฒŒ
 63
 64
 65     }

 

 

 

3. Nginx ์„œ๋ฒ„ html ํŒŒ์ผ

[root@WEB ~]# ls /usr/share/nginx/html/
404.html                     icons           style_contents.css
50x.html                     index.html      style_head.css
WebTest-php8-mariadb.tar.gz  member          system_noindex_logo.png
board                        nginx-logo.png  poweredby.png

 

html์™€ styleํŒŒ์ผ์„ nginx/html๊ฒฝ๋กœ์— ๋„ฃ๋Š”๋‹ค

 

 

 

4. php-fpm ์„œ๋ฒ„ conf ํŒŒ์ผ ์ˆ˜์ •

[root@WAS ~]# vim /etc/php-fpm.d/www.conf 

 20 ; Unix user/group of processes
 21 ; Note: The user is mandatory. If the group is not set, the default user's g    roup
 22 ;       will be used.
 23 ; RPM: apache user chosen to provide access to the same directories as httpd
 24 ;user = apache
 25 user = nginx  // nginx๋กœ ์„ค์ •
 26 ; RPM: Keep a group allowed to write in log dir.
 27 ;group = apache
 28 group = nginx // nginx๋กœ ์„ค์ •
...
 41 listen = 0.0.0.0:9000  // nginx conf ํŒŒ์ผ์˜ ํฌํŠธ๋ฒˆํ˜ธ์™€ ๋™์ผํ•ด์•ผํ•จ
...
 54 listen.owner = nginx // nginx๋กœ ์„ค์ •
 55 listen.group = nginx // nginx๋กœ ์„ค์ •
 56 listen.mode = 0660

 

 

5. php-fpm ์„œ๋ฒ„ html ํŒŒ์ผ

[root@WAS ~]# ls /usr/share/nginx/html/
WebTest-php8-mariadb.tar.gz  dbconn1.php       mysqli_query_insert.php
board                        head.php          mysqli_select_db.php
create_db.php                index.php         style_contents.css
db.sql                       info.php          style_head.css
dbconn.php                   member            test.php
dbconn.php.bak               mysqli_query.php  webtest_DB.sql

 

php-fpm ์„œ๋ฒ„๋Š” php ํŒŒ์ผ์„ ๋„ฃ๋Š”๋‹ค

nginx์„œ๋ฒ„ confํŒŒ์ผ ๊ฒฝ๋กœ๋Œ€๋กœ phpํŒŒ์ผ์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ด์•ผ ํ•œ๋‹ค.

 

 

6. ์„œ๋น„์Šค ์žฌ์‹œ์ž‘

[root@WEB ~]# systemctl restart nginx.service
[root@WAS ~]# systemctl restart php-fpm.service

 

 

7. ์™ธ๋ถ€ ํ˜ธ์ŠคํŠธ์—์„œ ์›นํŽ˜์ด์ง€ ํ™•์ธ

'IaC Application' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

3tier-service ์‹ค์Šต  (0) 2024.03.27