Linux,Unix,BSD

[Linux] Nginx + PHP7 설치 on CentOS 7

채윤아빠 2019. 12. 28. 17:53
728x90
반응형



외부 인터넷을 이용할 수 없는 IDC내의 CentOS 7 서버에 Nginx + PHP7을 설치하는 방법을 설명합니다.

nginx 및 PHP7 설치 패키지 다운로드

인터넷에 연결된 장비에서 Nginx 및 PHP7 설치를 위한 패키지들을 다음과 같이 다운로드 받습니다.

저장소 설정

Nginx 설치를 위해서는 "epel-release" 저장소를 다음과 같이 추가합니다.

yum install epel-release
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.kakao.com
 * extras: mirror.kakao.com
 * updates: mirror.kakao.com
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================
 Package                                               Arch                                            Version                                        Repository                                       Size
============================================================================================================================================================================================================
Installing:
 epel-release                                          noarch                                          7-11                                           extras                                           15 k

Transaction Summary
============================================================================================================================================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-11.noarch.rpm                                                                                                                                                         |  15 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-11.noarch                                                                                                                                                                 1/1
  Verifying  : epel-release-7-11.noarch                                                                                                                                                                 1/1

Installed:
  epel-release.noarch 0:7-11

Complete!

PHP7을 설치하기 위하여 다음과 같이 "remi" 저장소를 추가합니다.

curl http://rpms.remirepo.net/enterprise/remi-release-7.rpm -o remi-release-7.rpm                                                                                                      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 17908  100 17908    0     0   3263      0  0:00:05  0:00:05 --:--:--  4559

rpm -Uvh remi-release-7.rpm
warning: remi-release-7.rpm: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:remi-release-7.7-1.el7.remi      ################################# [100%]

yum-config-manager --enable remi-php73
Loaded plugins: fastestmirror
============================================================================================= repo: remi-php73 =============================================================================================
[remi-php73]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl =
cache = 0
cachedir = /var/cache/yum/x86_64/7/remi-php73

...

timeout = 30.0
ui_id = remi-php73
ui_repoid_vars = releasever,
   basearch

설치 패키지 다운로드

Nginx 패키지를 다음과 같이 다운로드 받습니다.

yum install nginx --downloadonly --downloaddir=/root/rpms/nginx-1.16.1-1 \

...

Dependencies Resolved

============================================================================================================================================================================================================
 Package                                                       Arch                                     Version                                                Repository                              Size
============================================================================================================================================================================================================
Installing:
 nginx                                                         x86_64                                   1:1.16.1-1.el7                                         epel                                   562 k
Installing for dependencies:
 centos-indexhtml                                              noarch                                   7-9.el7.centos                                         base                                    92 k
 dejavu-fonts-common                                           noarch                                   2.33-6.el7                                             base                                    64 k
 dejavu-sans-fonts                                             noarch                                   2.33-6.el7                                             base                                   1.4 M
 fontconfig                                                    x86_64                                   2.13.0-4.3.el7                                         base                                   254 k
 fontpackages-filesystem                                       noarch                                   1.44-8.el7                                             base                                   9.9 k
 gd                                                            x86_64                                   2.0.35-26.el7                                          base                                   146 k
 gperftools-libs                                               x86_64                                   2.6.1-1.el7                                            base                                   272 k
 libX11                                                        x86_64                                   1.6.7-2.el7                                            base                                   607 k
 libX11-common                                                 noarch                                   1.6.7-2.el7                                            base                                   164 k
 libXau                                                        x86_64                                   1.0.8-2.1.el7                                          base                                    29 k
 libXpm                                                        x86_64                                   3.5.12-1.el7                                           base                                    55 k
 libjpeg-turbo                                                 x86_64                                   1.2.90-8.el7                                           base                                   135 k
 libxcb                                                        x86_64                                   1.13-1.el7                                             base                                   214 k
 libxslt                                                       x86_64                                   1.1.28-5.el7                                           base                                   242 k
 nginx-all-modules                                             noarch                                   1:1.16.1-1.el7                                         epel                                    19 k
 nginx-filesystem                                              noarch                                   1:1.16.1-1.el7                                         epel                                    21 k
 nginx-mod-http-image-filter                                   x86_64                                   1:1.16.1-1.el7                                         epel                                    30 k
 nginx-mod-http-perl                                           x86_64                                   1:1.16.1-1.el7                                         epel                                    39 k
 nginx-mod-http-xslt-filter                                    x86_64                                   1:1.16.1-1.el7                                         epel                                    29 k
 nginx-mod-mail                                                x86_64                                   1:1.16.1-1.el7                                         epel                                    57 k
 nginx-mod-stream                                              x86_64                                   1:1.16.1-1.el7                                         epel                                    84 k
 perl                                                          x86_64                                   4:5.16.3-294.el7_6                                     base                                   8.0 M
 perl-Carp                                                     noarch                                   1.26-244.el7                                           base                                    19 k
 perl-Encode                                                   x86_64                                   2.51-7.el7                                             base                                   1.5 M
 perl-Exporter                                                 noarch                                   5.68-3.el7                                             base                                    28 k
 perl-File-Path                                                noarch                                   2.09-2.el7                                             base                                    26 k
 perl-File-Temp                                                noarch                                   0.23.01-3.el7                                          base                                    56 k
 perl-Filter                                                   x86_64                                   1.49-3.el7                                             base                                    76 k
 perl-Getopt-Long                                              noarch                                   2.40-3.el7                                             base                                    56 k
 perl-HTTP-Tiny                                                noarch                                   0.033-3.el7                                            base                                    38 k
 perl-PathTools                                                x86_64                                   3.40-5.el7                                             base                                    82 k
 perl-Pod-Escapes                                              noarch                                   1:1.04-294.el7_6                                       base                                    51 k
 perl-Pod-Perldoc                                              noarch                                   3.20-4.el7                                             base                                    87 k
 perl-Pod-Simple                                               noarch                                   1:3.28-4.el7                                           base                                   216 k
 perl-Pod-Usage                                                noarch                                   1.63-3.el7                                             base                                    27 k
 perl-Scalar-List-Utils                                        x86_64                                   1.27-248.el7                                           base                                    36 k
 perl-Socket                                                   x86_64                                   2.010-4.el7                                            base                                    49 k
 perl-Storable                                                 x86_64                                   2.45-3.el7                                             base                                    77 k
 perl-Text-ParseWords                                          noarch                                   3.29-4.el7                                             base                                    14 k
 perl-Time-HiRes                                               x86_64                                   4:1.9725-3.el7                                         base                                    45 k
 perl-Time-Local                                               noarch                                   1.2300-2.el7                                           base                                    24 k
 perl-constant                                                 noarch                                   1.27-2.el7                                             base                                    19 k
 perl-libs                                                     x86_64                                   4:5.16.3-294.el7_6                                     base                                   688 k
 perl-macros                                                   x86_64                                   4:5.16.3-294.el7_6                                     base                                    44 k
 perl-parent                                                   noarch                                   1:0.225-244.el7                                        base                                    12 k
 perl-podlators                                                noarch                                   2.5.1-3.el7                                            base                                   112 k
 perl-threads                                                  x86_64                                   1.87-4.el7                                             base                                    49 k
 perl-threads-shared                                           x86_64                                   1.43-6.el7                                             base                                    39 k

Transaction Summary
============================================================================================================================================================================================================
Install  1 Package (+48 Dependent packages)

Total download size: 16 M
Installed size: 51 M

PHP-7.3 패키지를 다음과 같이 다운로드 받습니다.

yum install --downloadonly --downloaddir=/root/rpms/php-7.3.12-1 \
    php php-fpm php-cli php-pear php-xdebug php-redis \
    php-opcache php-mysqli php-mysqlnd php-pecl-memcache \
    php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml \
    php-bz2 php-zip php-dom php-gettext php-xmlreader php-xmlwriter \
    php-tokenizer php-xmlrpc php-curl php-ctype php-session

...

============================================================================================================================================================================================================
 Package                                                Arch                                  Version                                                       Repository                                 Size
============================================================================================================================================================================================================
Installing:
 php                                                    x86_64                                7.3.12-1.el7.remi                                             remi-php73                                3.2 M
 php-cli                                                x86_64                                7.3.12-1.el7.remi                                             remi-php73                                4.9 M
 php-common                                             x86_64                                7.3.12-1.el7.remi                                             remi-php73                                1.1 M
 php-fpm                                                x86_64                                7.3.12-1.el7.remi                                             remi-php73                                1.7 M
 php-gd                                                 x86_64                                7.3.12-1.el7.remi                                             remi-php73                                 81 k
 php-mbstring                                           x86_64                                7.3.12-1.el7.remi                                             remi-php73                                510 k
 php-mysqlnd                                            x86_64                                7.3.12-1.el7.remi                                             remi-php73                                234 k
 php-opcache                                            x86_64                                7.3.12-1.el7.remi                                             remi-php73                                309 k
 php-pear                                               noarch                                1:1.10.10-2.el7.remi                                          remi-php73                                361 k
 php-pecl-mcrypt                                        x86_64                                1.0.3-1.el7.remi.7.3                                          remi-php73                                 30 k
 php-pecl-memcache                                      x86_64                                4.0.4-1.el7.remi.7.3                                          remi-php73                                 85 k
 php-pecl-memcached                                     x86_64                                3.1.4-1.el7.remi.7.3                                          remi-php73                                 86 k
 php-pecl-redis5                                        x86_64                                5.1.1-1.el7.remi.7.3                                          remi-php73                                230 k
 php-pecl-xdebug                                        x86_64                                2.8.0-1.el7.remi.7.3                                          remi-php73                                237 k
 php-pecl-zip                                           x86_64                                1.15.5-1.el7.remi.7.3                                         remi-php73                                 51 k
 php-xml                                                x86_64                                7.3.12-1.el7.remi                                             remi-php73                                207 k
 php-xmlrpc                                             x86_64                                7.3.12-1.el7.remi                                             remi-php73                                 84 k
Installing for dependencies:
 apr                                                    x86_64                                1.4.8-5.el7                                                   base                                      103 k
 apr-util                                               x86_64                                1.5.2-6.el7                                                   base                                       92 k
 dejavu-fonts-common                                    noarch                                2.33-6.el7                                                    base                                       64 k
 dejavu-sans-fonts                                      noarch                                2.33-6.el7                                                    base                                      1.4 M
 fastlz                                                 x86_64                                0.1.0-0.1.20070619svnrev12.el7                                epel                                      9.8 k
 fontconfig                                             x86_64                                2.13.0-4.3.el7                                                base                                      254 k
 fontpackages-filesystem                                noarch                                1.44-8.el7                                                    base                                      9.9 k
 gd-last                                                x86_64                                2.2.5-10.el7.remi                                             remi-safe                                 134 k
 httpd                                                  x86_64                                2.4.6-90.el7.centos                                           base                                      2.7 M
 httpd-tools                                            x86_64                                2.4.6-90.el7.centos                                           base                                       91 k
 jbigkit-libs                                           x86_64                                2.0-11.el7                                                    base                                       46 k
 libX11                                                 x86_64                                1.6.7-2.el7                                                   base                                      607 k
 libX11-common                                          noarch                                1.6.7-2.el7                                                   base                                      164 k
 libXau                                                 x86_64                                1.0.8-2.1.el7                                                 base                                       29 k
 libXpm                                                 x86_64                                3.5.12-1.el7                                                  base                                       55 k
 libargon2                                              x86_64                                20161029-3.el7                                                epel                                       23 k
 libevent                                               x86_64                                2.0.21-4.el7                                                  base                                      214 k
 libjpeg-turbo                                          x86_64                                1.2.90-8.el7                                                  base                                      135 k
 liblzf                                                 x86_64                                3.6-7.el7                                                     epel                                       22 k
 libmcrypt                                              x86_64                                2.5.8-13.el7                                                  epel                                       99 k
 libmemcached-opt-libs                                  x86_64                                1.0.18-2.el7.remi                                             remi-safe                                 127 k
 libtiff                                                x86_64                                4.0.3-32.el7                                                  base                                      171 k
 libwebp7                                               x86_64                                1.0.2-1.el7.remi                                              remi-safe                                 265 k
 libxcb                                                 x86_64                                1.13-1.el7                                                    base                                      214 k
 libxslt                                                x86_64                                1.1.28-5.el7                                                  base                                      242 k
 libzip5                                                x86_64                                1.5.2-1.el7.remi                                              remi-safe                                  56 k
 libzstd                                                x86_64                                1.4.2-1.el7                                                   epel                                      252 k
 mailcap                                                noarch                                2.1.41-2.el7                                                  base                                       31 k
 oniguruma5                                             x86_64                                6.9.4-1.el7.remi                                              remi-safe                                 197 k
 php-fedora-autoloader                                  noarch                                1.0.0-1.el7                                                   epel                                      9.6 k
 php-json                                               x86_64                                7.3.12-1.el7.remi                                             remi-php73                                 66 k
 php-pdo                                                x86_64                                7.3.12-1.el7.remi                                             remi-php73                                127 k
 php-pecl-igbinary                                      x86_64                                3.0.1-2.el7.remi.7.3                                          remi-php73                                111 k
 php-pecl-msgpack                                       x86_64                                2.0.3-1.el7.remi.7.3                                          remi-php73                                 55 k
 php-process                                            x86_64                                7.3.12-1.el7.remi                                             remi-php73                                 83 k

Transaction Summary
============================================================================================================================================================================================================
Install  17 Packages (+35 Dependent packages)

Total download size: 22 M
Installed size: 79 M

다운로드 받은 패키지 파일들을 tar로 묶은 후에, IDC내 서버로 복사합니다.

cd /root/rpms
tar cf nginx-1.16.1-1.tar nginx-1.16.1-1/
tar cf php-7.3.12-1.tar php-7.3.12-1/
scp -P1022 *.tar root@172.16.112.70:/home/nfs/backup/rpms

IDC 서버내 Nginx + PHP7 설치

사전 준비

다음과 같이 apache, nginx 계정 및 그룹을 생성합니다.

groupadd --gid 48 apache ; useradd --gid 48 --uid 48 -r apache ; \
groupadd --gid 981 nginx ; useradd --gid 981 --uid 981 -r nginx

내부 방화벽이 활성화되어 있는 경우에는 다음과 같이 http 및 https에 대한 방화벽을 미리 열어 둡니다.

firewall-cmd --permanent --zone=public --add-service=http ; \
firewall-cmd --permanent --zone=public --add-service=https ; \
firewall-cmd --reload

tar로 묶어 업로드한 패키지 파일들을 풀어서 설치를 준비합니다.

cd /home/nfs/backup/rpms
tar xf nginx-1.16.1-1.tar
tar xf php-7.3.12-1.tar

Nginx, PHP7 패키지 설치

다음과 같이 Nginx 및 PHP7 패키지를 순차적으로 설치합니다.

cd /home/nfs/backup/rpms/nginx-1.16.1-1
rpm Uvh --replacepkgs *rpm
warning: nginx-1.16.1-1.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:perl-parent-1:0.225-244.el7      ################################# [  2%]
   2:perl-HTTP-Tiny-0.033-3.el7       ################################# [  4%]
   3:perl-podlators-2.5.1-3.el7       ################################# [  6%]
   4:perl-Pod-Perldoc-3.20-4.el7      ################################# [  8%]
   5:perl-Pod-Escapes-1:1.04-294.el7_6################################# [ 10%]
   6:perl-Text-ParseWords-3.29-4.el7  ################################# [ 12%]
   7:perl-Encode-2.51-7.el7           ################################# [ 14%]
   8:perl-Pod-Usage-1.63-3.el7        ################################# [ 16%]
   9:perl-constant-1.27-2.el7         ################################# [ 18%]
  10:perl-Carp-1.26-244.el7           ################################# [ 20%]
  11:perl-Exporter-5.68-3.el7         ################################# [ 22%]
  12:perl-Filter-1.49-3.el7           ################################# [ 24%]
  13:perl-libs-4:5.16.3-294.el7_6     ################################# [ 27%]
  14:perl-macros-4:5.16.3-294.el7_6   ################################# [ 29%]
  15:perl-File-Path-2.09-2.el7        ################################# [ 31%]
  16:perl-File-Temp-0.23.01-3.el7     ################################# [ 33%]
  17:perl-PathTools-3.40-5.el7        ################################# [ 35%]
  18:perl-Scalar-List-Utils-1.27-248.e################################# [ 37%]
  19:perl-Socket-2.010-4.el7          ################################# [ 39%]
  20:perl-Storable-2.45-3.el7         ################################# [ 41%]
  21:perl-threads-1.87-4.el7          ################################# [ 43%]
  22:perl-threads-shared-1.43-6.el7   ################################# [ 45%]
  23:perl-Time-HiRes-4:1.9725-3.el7   ################################# [ 47%]
  24:perl-Pod-Simple-1:3.28-4.el7     ################################# [ 49%]
  25:perl-Getopt-Long-2.40-3.el7      ################################# [ 51%]
  26:perl-Time-Local-1.2300-2.el7     ################################# [ 53%]
  27:perl-4:5.16.3-294.el7_6          ################################# [ 55%]
  28:fontpackages-filesystem-1.44-8.el################################# [ 57%]
  29:dejavu-fonts-common-2.33-6.el7   ################################# [ 59%]
  30:dejavu-sans-fonts-2.33-6.el7     ################################# [ 61%]
  31:fontconfig-2.13.0-4.3.el7        ################################# [ 63%]
  32:nginx-filesystem-1:1.16.1-1.el7  ################################# [ 65%]
  33:libxslt-1.1.28-5.el7             ################################# [ 67%]
  34:libXau-1.0.8-2.1.el7             ################################# [ 69%]
  35:libxcb-1.13-1.el7                ################################# [ 71%]
  36:libX11-common-1.6.7-2.el7        ################################# [ 73%]
  37:libX11-1.6.7-2.el7               ################################# [ 76%]
  38:libXpm-3.5.12-1.el7              ################################# [ 78%]
  39:libjpeg-turbo-1.2.90-8.el7       ################################# [ 80%]
  40:gd-2.0.35-26.el7                 ################################# [ 82%]
  41:gperftools-libs-2.6.1-1.el7      ################################# [ 84%]
  42:centos-indexhtml-7-9.el7.centos  ################################# [ 86%]
  43:nginx-mod-http-image-filter-1:1.1################################# [ 88%]
  44:nginx-mod-http-perl-1:1.16.1-1.el################################# [ 90%]
  45:nginx-mod-http-xslt-filter-1:1.16################################# [ 92%]
  46:nginx-mod-mail-1:1.16.1-1.el7    ################################# [ 94%]
  47:nginx-all-modules-1:1.16.1-1.el7 ################################# [ 96%]
  48:nginx-1:1.16.1-1.el7             ################################# [ 98%]
  49:nginx-mod-stream-1:1.16.1-1.el7  ################################# [100%]

cd /home/nfs/backup/rpms/php-7.3.12-1
rpm Uvh --replacepkgs *rpm
warning: fastlz-0.1.0-0.1.20070619svnrev12.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
warning: gd-last-2.2.5-10.el7.remi.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:php-json-7.3.12-1.el7.remi       ################################# [  2%]
   2:php-common-7.3.12-1.el7.remi     ################################# [  4%]
   3:libjpeg-turbo-1.2.90-8.el7       ################################# [  6%]
   4:libargon2-20161029-3.el7         ################################# [  8%]
   5:apr-1.4.8-5.el7                  ################################# [ 10%]
   6:apr-util-1.5.2-6.el7             ################################# [ 12%]
   7:php-cli-7.3.12-1.el7.remi        ################################# [ 13%]
   8:php-pecl-igbinary-3.0.1-2.el7.rem################################# [ 15%]
   9:php-pecl-msgpack-2.0.3-1.el7.remi################################# [ 17%]
  10:fontpackages-filesystem-1.44-8.el################################# [ 19%]
  11:dejavu-fonts-common-2.33-6.el7   ################################# [ 21%]
  12:dejavu-sans-fonts-2.33-6.el7     ################################# [ 23%]
  13:fontconfig-2.13.0-4.3.el7        ################################# [ 25%]
  14:httpd-tools-2.4.6-90.el7.centos  ################################# [ 27%]
  15:php-fedora-autoloader-1.0.0-1.el7################################# [ 29%]
  16:php-pdo-7.3.12-1.el7.remi        ################################# [ 31%]
  17:php-process-7.3.12-1.el7.remi    ################################# [ 33%]
  18:oniguruma5-6.9.4-1.el7.remi      ################################# [ 35%]
  19:mailcap-2.1.41-2.el7             ################################# [ 37%]
  20:httpd-2.4.6-90.el7.centos        ################################# [ 38%]
  21:libzstd-1.4.2-1.el7              ################################# [ 40%]
  22:libzip5-1.5.2-1.el7.remi         ################################# [ 42%]
  23:libxslt-1.1.28-5.el7             ################################# [ 44%]
  24:php-xml-7.3.12-1.el7.remi        ################################# [ 46%]
  25:libXau-1.0.8-2.1.el7             ################################# [ 48%]
  26:libxcb-1.13-1.el7                ################################# [ 50%]
  27:libX11-common-1.6.7-2.el7        ################################# [ 52%]
  28:libX11-1.6.7-2.el7               ################################# [ 54%]
  29:libXpm-3.5.12-1.el7              ################################# [ 56%]
  30:libwebp7-1.0.2-1.el7.remi        ################################# [ 58%]
  31:libmcrypt-2.5.8-13.el7           ################################# [ 60%]
  32:liblzf-3.6-7.el7                 ################################# [ 62%]
  33:libevent-2.0.21-4.el7            ################################# [ 63%]
  34:libmemcached-opt-libs-1.0.18-2.el################################# [ 65%]
  35:jbigkit-libs-2.0-11.el7          ################################# [ 67%]
  36:libtiff-4.0.3-32.el7             ################################# [ 69%]
  37:gd-last-2.2.5-10.el7.remi        ################################# [ 71%]
  38:fastlz-0.1.0-0.1.20070619svnrev12################################# [ 73%]
  39:php-pecl-memcached-3.1.4-1.el7.re################################# [ 75%]
  40:php-gd-7.3.12-1.el7.remi         ################################# [ 77%]
  41:php-pecl-redis5-5.1.1-1.el7.remi.################################# [ 79%]
  42:php-pecl-mcrypt-1.0.3-1.el7.remi.################################# [ 81%]
  43:php-pear-1:1.10.10-2.el7.remi    ################################# [ 83%]
  44:php-xmlrpc-7.3.12-1.el7.remi     ################################# [ 85%]
  45:php-pecl-zip-1.15.5-1.el7.remi.7.################################# [ 87%]
  46:php-7.3.12-1.el7.remi            ################################# [ 88%]
  47:php-mbstring-7.3.12-1.el7.remi   ################################# [ 90%]
  48:php-mysqlnd-7.3.12-1.el7.remi    ################################# [ 92%]
  49:php-fpm-7.3.12-1.el7.remi        ################################# [ 94%]
  50:php-opcache-7.3.12-1.el7.remi    ################################# [ 96%]
  51:php-pecl-memcache-4.0.4-1.el7.rem################################# [ 98%]
  52:php-pecl-xdebug-2.8.0-1.el7.remi.################################# [100%]

설치된 Nginx 및 PHP7의 버전을 확인합니다.

nginx -v
nginx version: nginx/1.16.1

php -v
PHP 7.3.12 (cli) (built: Nov 19 2019 10:24:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.12, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.12, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.8.0, Copyright (c) 2002-2019, by Derick Rethans

환경설정

Nginx 환경설정

/etc/nginx/nginx.conf 파일에서 다음 부분들을 수정합니다.

#user nginx; # "apache" 계정 (gid=48/uid=48)으로 운영
user apache;
#worker_processes auto;
worker_processes 1; # 동작 프로세스는 1개만

...

events {
#    worker_connections 1024; # 대용량 처리를 위하여 동시 접속수를 8K로 늘립니다.
    worker_connections 8196;
}

http {

...

    # proxy를 거쳐서 들어온 요청에 대한 로깅 포맷 ; 실 클라이언트의 IP 주소를 기록하도록 함
    log_format  proxy  '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
            '$status $body_bytes_sent "$http_referer" '
            '"$http_user_agent" "$remote_addr"';

...

신규 사이트들을 위한 설정 폴더를 생성합니다.

mkdir -p /etc/nginx/sites-available ; cd /etc/nginx/sites-available

다음과 같이 새로운 사이트에 대한 설정 파일을 생성합니다.

vi any_https.conf

server {
    listen   443;
    server_name 10.70.150.23 smtp1.we-builder.co.kr smtp1.wbuilder.net;

    # 날짜별 로깅을 위한 변수 설정
    if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
        set $year $1;
        set $month $2;
        set $day $3;
    }

    # proxy IP 헤더(http-x-forward-for)에 대한 처리
    set $xff $http_x_forwarded_for;
    set $main_log 0;
    set $proxy_log 1;
    if ($xff = "") {
        set $proxy_log 0;
        set $main_log 1;
    }

    # proxy를 거쳐온 것과 직접 접속한 것의 로깅 포맷을 구분하여 처리하도록 함 ; 실 클라이언트 IP가 REMOTE_ADDR에 기록되도록 함
    access_log /home/weblogs/any_https/access_log.$year$month$day proxy if=$proxy_log;
    access_log /home/weblogs/any_https/access_log.$year$month$day main if=$main_log;
    error_log /home/weblogs/any_https/error_log debug;

    # original = /usr/share/nginx/html
    root   /home/nfs/service/any_https;
    index index.php index.html index.htm;

    # 오류 페이지에 대한 설정 ; 앞서 설정한 "root"를 기준으로 실제 파일의 위치 설정
    error_page 403 /403.html;
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;

    location = /favicon.ico { access_log off; log_not_found off; break; }
    location = /robots.txt  { access_log off; log_not_found off; break; }

    location ~ /\.htaccess$ {
        return 404;
    }
    # Deny for accessing codes
    location ~ ^/(\.git|\.htaccess|application|sql|system|tests)/ {
        return 404;
    }

    # CodeIgniter를 위한 rewrite 설정
    location / {
        try_files $uri $uri/ /index.php$request_uri;
    }

    # PHP 파일 처리
    location ~ \.php(/|$) {
        # PHP-fpm으로 처리하기 위한 설정들
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        try_files $fastcgi_script_name =404;
        set $path_info $fastcgi_path_info;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        # CodeIgniter 환경변수 ; production = 불필요한 PHP 오류 표시 제거 (Notice, Warning)
        fastcgi_param CI_ENV production;
        # WebBuilder 환경변수 ; WBENV_LIVE_DOUZONE = 운영계에 맞추어 동작
        fastcgi_param WBENV WBENV_LIVE_DOUZONE;
        include fastcgi_params;
    }
}

다음과 같이 새로 작성한 사이트 설정 파일에 대하여, 심볼릭 링크를 만들어서 nginx에서 해당 사이트가 동작되도록 합니다.

ln -s /etc/nginx/sites-available/any_https.conf /etc/nginx/conf.d/any_https.conf

php-fpm 환경설정

"/etc/php-fpm.d/www.conf" 파일을 수정합니다.

; RPM: apache user chosen to provide access to the same directories as httpd
user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache

;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock

listen.owner = apache
listen.group = apache

; at http://php.net/session.save-path ; 세션 관련 부분에서 오류가 발생할 수 있으므로, 아래 설정은 주석으로 변경합니다.
;php_value[session.save_handler] = files
;php_value[session.save_path]    = /var/lib/php/session
;php_value[soap.wsdl_cache_dir]  = /var/lib/php/wsdlcache

php.ini 환경설정

"/etc/php.ini" 파일을 다음과 같이 수정합니다.

;short_open_tag = Off
short_open_tag = On

;memory_limit = 128M
memory_limit = 256M

;post_max_size = 8M
post_max_size = 208M

;upload_max_filesize = 2M
upload_max_filesize = 200M

;mysqli.default_port = 3306
mysqli.default_port = 16033

웹서비스 구동 및 시험

다음과 같이 php-fpm 서비스를 시작합니다.

systemctl start php-fpm

다음과 같이 nginx 서비스를 시작합니다.

systemctl start nginx

nginx 서비스가 시작된 후에 curl 명령을 이용하여 추가한 사이트에 대한 웹 서비스가 정상적으로 동작하는지 확인합니다.

systemctl status nginx
curl -v "http://10.70.150.23:443/index.html" 

참고자료