'2016/04/06'에 해당되는 글 4건

  1. 2016.04.06 Centos6에 Nginx+PHP7-FPM+MySQL Yum으로 설치
  2. 2016.04.06 Remi Repo 설치(PHP7)
  3. 2016.04.06 EPEL 패키지 설치
  4. 2016.04.06 PHP 운영구성 관련 정리 #3
2016. 4. 6. 14:48

Centos6에 Nginx+PHP7-FPM+MySQL Yum으로 설치

요 근래 Nginx + PHP-FPM 글을 몇개 번역한걸 올렸더니 갑자기 궁금해져서 설치를 해보고 메모해둠


1. MySQL 설치

별로 신경을 안쓰고 있었는데 MySQL쪽에도 Yum Repo를 제공하고 있었다...


http://dev.mysql.com/downloads/repo/yum/


이 링크에서 버전에 맞게 설치하면 된다. Centos6은 Red Hat Enterprise Linux 6을 다운 받으면 됨.


2.PHP7 설치

아래 링크를 참고해서 설치

https://webtatic.com/packages/php70/


또는

http://wyseburn.tistory.com/entry/Remi-Repo-%EC%84%A4%EC%B9%98PHP7


다만 이걸로 설치를 하면 경로가 좀 요상해진다.

환경관련파일은 /etc/opt/remi/php70/ 에 있고 로그는 /var/opt/remi/php70/ 에 있으니 주의.

그리고 실행파일을 /usr/bin/php70 이런식인데 실제로는 /opt/remi/php70/root/usr/bin 에 php, php-config, phpize 등이 있으니 주의, 소프트링크를 하면 좀 나을꺼다.


그리고 php70.x86_64 와 php70-php.x86_64 같이 똑같을꺼 같은 패키지가 있는데 버전을 보면 다르니

php70-php 로 시작하는 것들(현재 버전 7.0.5)로 깔면 된다. 물론 FPM으로 돌릴꺼니 php70-php-fpm.x86_64은 꼭 받아야겠지. 아래는 설치패키지.


php70-php-bcmath.x86_64

php70-php-cli.x86_64

php70-php-common.x86_64

php70-php-devel.x86_64

php70-php-fpm.x86_64

php70-php-gd.x86_64

php70-php-json.x86_64

php70-php-mbstring.x86_64

php70-php-mcrypt.x86_64

php70-php-mysqlnd.x86_64

php70-php-opcache.x86_64

php70-php-pdo.x86_64

php70-php-suhosin.x86_64

php70-runtime.x86_64


/etc/opt/remi/php70/php-fpm.d/www.conf 파일을 열어 수정하자.

user = apache                       #사용자는 일반계정을 만들어 사용할 것. apache는 이미 있어서 사용

group = apache

listen = /var/run/php7-fpm.sock   #처음에는 127.0.0.1:9000 인데 서버가 하나면 unix socket로 바꾸는게 났다.

listen.owner = apache              #권한도 맞춰줘야함, 계정은 nginx의 user와 같아야 한다.

listen.group = apache

listen.mode = 0660


service php70-php-fpm start        #fpm 데몬이름도 거시기 하다.



php를 fpm으로 실행할 경우 php.ini 파일에 cgi.fix_pathinfo = 1 인 경우 http://localhost/bad.hack/aa.php 와 같이 bad.hack 을 실행 가능하게 하므로 cgi.fix_pathinfo = 0 으로 하자.


3. Nginx 최신버전 설치


[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/6/$basearch/ 

gpgcheck=0

enabled=1


이 내용을 /etc/yum.repos.d/nginx.repo 파일로 만들어주면 최신버전을 yum으로 관리할 수 있게된다.

baseurl에 /6/ 은 리눅스 버전을 의미하니 다른 버전이라면 바꿔도 된다.

어떤게 있는지 궁금하면 브라우저로 http://nginx.org/packages 로 들어가보면 리눅스 배포판별로 확인할 수 있으니 들어가보는것도 나쁘지 않다.

주의 : epel Repo에도 Nginx 가 있는데 버전이 낮으니 사용하지 말것.


/etc/nginx/nginx.conf 수정

수정할꺼는 많겠지만 간단하게 몇가지만 수정하거나 추가한다.


user apache;           #php-fpm 에 user와 동일해야 한다.

worker_processes 1;  #cpu core 갯수

http {

    access_log off;     #로그는 끄자

    server_tokens off;  #서버정보를 표시하는거도 끄자

    fastcgi_hide_header X-Powered-By; #불필요한 정보표시 끄기
    fastcgi_hide_header X-Pingback;
    fastcgi_hide_header Link;
    proxy_hide_header X-Powered-By;
    proxy_hide_header X-Pingback;
    proxy_hide_header X-Link;

    add_header X-Frame-Options SAMEORIGIN; #아이프래임 사용 SAMEORIGIN 같은도메인 가능, DENY 불가, ALLOW 모두가능
    add_header X-Content-Type-Options nosniff; #잘못된 MIME에는 응답거부
    add_header X-XSS-Protection "1; mode=block"; #XSS 세션 하이재킹 방지

    include /etc/nginx/sites-enabled/*.conf   #vhost 를 sites-enabled 디렉토리에서 관리

}


vhost설정은 대충 conf.d/default.conf 를 새로만든 sites-enabled 디렉토리에 다른이름으로 복사해서 관리한다.

수정할 부분은 밑에 몇개정도.

server_name  domain.com *.domain.com;

root   /home/sms/public_html; #root는 location /와 location ~\.php 블럭안에 각각정의되 있는데 밖으로 뺀다.

location ~ \.php$ {

    fastcgi_pass   unix:/var/run/php7-fpm.sock;   #/etc/opt/remi/php70/php-fpm.d/www.conf listen 부분과 일치해야된다.

    fastcgi_index  index.php;

    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

    include        fastcgi_params;

}


특정 디렉토리에 PHP 파싱을 차단하려면(예 data, upload, files/my) 아래 내용을 반드시!! location ~ \.php$ {} 블럭 앞에 정의해야 한다.

location ~ /(data|upload|files/my)/.*\.(php\d?|p?html?|pl|cgi) {
    return 403;
}


/etc/nginx/fastcgi_params 파일 맨위에 추가


set $fastcgi_script_realname $fastcgi_script_name;

if ( $fastcgi_script_name ~ ^(.*\.php)(/.*)$ ) {

    set $fastcgi_script_realname $1;

    set $path_info $2;

}

if (!-f $document_root$fastcgi_script_realname) {

    return 404;

}


이부분은 http://도메인/aaa.gif/aaa.php 와 같이 호출될때 aaa.gif에 php코드가 있으면 실행되는데 그걸 방지


service nginx start


이걸로 끝. 보안설정이나 튜닝관련은 다른 문서를 찾아봐야할듯.


4. 아래와 같은 오류가 발생할 경우(/var/lib/nginx/tmp/fastcgi 퍼미션오류)


2016/04/08 08:26:48 [crit] 1967#0: *1 open() "/var/lib/nginx/tmp/fastcgi/1/00/0000000001" failed (13: 

Permission denied) while reading upstream, client: 1.2.3.4, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm.sock:", host: "domain.com"


아마존 ec2 에서는 최신버전을 yum으로 설치가능하길래 그냥 설치를 했다.

설치하다 nginx.conf 에 user가 nginx로 되있는 걸 무심결에 apache로 고쳤는데 이게 원인이 되었다. 

문제는 /var/lib/nginx 소유자가 nginx.nginx 여서 발생하는 문제.... apache 로 수정하면 오류가 발생하지 않는다.

안된다면 /var/lib/nginx/tmp/fastcgi 의 권한을 777 로도 해볼것.


또 /etc/php-fpm.d/www.conf 에 보면 세션 저장 디렉토리가 별도로 설정되있다.

기본경로 : /var/lib/php/session

사용자를 변경할 경우 반드시 위 디렉토리의 소유 그룹도 변경해야 세션에 문제가 없다.

추가로 /var/lib/php/wsdlcache 의 소유 그룹도 변경하자.

/var/lib/php는 remi repo를 사용할 경우 /var/opt/remi/php70/lib/php 이니 주의.



.... an upstream response is buffered to a temporary file ....

오류가 발생한다면

fastcgi_max_temp_file_size 0; 을 추가


POST 메소드로 정적페이지(아무 값도 없이) 호출하는 경우 405 오류가 발생한다.

당연히 POST 는 값을 전송할떄 쓰는건데 잘못된 사용이니 오류나는게 맞지만 대부분 대충 쓰기때문에..

아래 내용을 추가하면 405 오류를 200(OK)로 바꿔준다.

error_page  405     =200 $uri;


5. /home/계정 디렉토리 퍼미션은 701로 해야한다. 자꾸 까먹네.

..


2016. 4. 6. 10:06

Remi Repo 설치(PHP7)

Remi repository 설치

http://rpms.remirepo.net/

Remi는 LAMP 기반의 최신 패키지를 제공하는 repository이다. Remi 저장소를 사용하기 위해서는 epel 저장소가 설정되어야 한다.

RHEL 7/CentOS 7

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

RHEL 6/CentOS 6

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

RHEL 5/CentOS 5

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm


다만 이걸로 설치를 하면 경로가 좀 요상해진다.

환경관련파일은 /etc/opt/remi/php70/ 에 있고 로그는 /var/opt/remi/php70/ 에 있으니 주의.

그리고 실행파일이 /usr/bin/php70 이런식인데 실제로는 /opt/remi/php70/root/usr/bin 에 php, php-config, phpize 등이 있으니 주의

2016. 4. 6. 10:04

EPEL 패키지 설치

CentOS 7 / RHEL 7

rpm -Uvh http://mirror.premi.st/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

CentOS 6 / RHEL 6

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm


CentOS 5 / RHEL 5

rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

 

Useful packages from the EPEL repo that I commonly use:

package
description
 
apachetop 

ApacheTop watches a logfile generated by Apache (in standard common or
: combined logformat, although it doesn't (yet) make use of any of the extra
: fields in combined) and generates human-parsable output in realtime.

 

atop

An advanced interactive monitor for Linux-systems to view the load on
: system-level and process-level.

 
munin

Munin is a highly flexible and powerful solution used to create graphs
: of virtually everything imaginable throughout your network, while still
: maintaining a rattling ease of installation and configuration.

 
ntop

ntop is a network traffic probe that shows the network usage, similar to what
: the popular top Unix command does.


2016. 4. 6. 09:51

PHP 운영구성 관련 정리 #3

mod_fastcgi 설치

소스 다운로드
cd /opt/src
wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz
압축 및 컴파일
tar zxvf mod_fastcgi-current.tar.gz
cd mod_fastcgi-2.4.6/
cp Makefile.AP2 Makefile
make top_dir=/usr/lib64/httpd
make install top_dir=/usr/lib64/httpd
설치 이진 확인
ldd /usr/lib64/httpd/modules/mod_fastcgi.so
        linux-vdso.so.1 =>  (0x00007ffffeeea000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f478e38c000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f478dff8000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003b69000000)

Apache2 / FastCGI 설정 (PHP-FPM)

성능 비교를 위해 확장자를 임시로 ".fphp"로 설정하고 있습니다. 실전 운용시에는 ".php"로 되돌립니다. Location 설정은 URL에 직접 액세스를 방지 내용입니다.Action 내부 리다이렉션 후 fcgi-bin URL을 사용할 수 있도록하기 위해 'env = REDIRECT_STATUS "을 설정합니다.

cat > "/etc/httpd/conf.d/php-fpm.conf" <<'EOF'
LoadModule fastcgi_module modules/mod_fastcgi.so
<FilesMatch "\.(fphp|html)$">
    SetHandler application/x-httpd-php
</FilesMatch>
Action application/x-httpd-php /fcgi-bin/php-fpm virtual
Alias /fcgi-bin/php-fpm /fcgi-bin-php-fpm
<Location /fcgi-bin/php-fpm>
    Order Deny,Allow
    Deny from All
    Allow from env=REDIRECT_STATUS
</Location>
FastCgiExternalServer /fcgi-bin-php-fpm -appConnTimeout 10 -idle-timeout 250 -socket /var/run/php-fpm.sock -pass-header Authorization
EOF

★ 중요 ★ 위 설정에서 "-appConnTimeout 10 -idle-timeout 250"은 반드시 설정해야합니다. idele-timeout은 기본적으로 30 초로되어 있지만, 경우에 따라서는 충분하지 않기 때문에 길게 설정해야합니다. "FastCGI : incomplete headers (0 bytes) received ...."오류가 토출 응답하지 않을 경우가 드물게 있습니다. 이 오류가 발생했을 때 "- idle-timeout"시간을 더 길게 설정하여 해결할 수 있습니다. 자세한 내용은 다음 사이트를 참조하십시오.

FastCGI 설치 설명서 :http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html

PHP-FPM 서비스 확인 및 등록

서비스 동작 테스트
service php-fpm start
service php-fpm stop
서비스에 추가 테스트
chkconfig php-fpm on
서비스에서 제거 테스트
chkconfig php-fpm off
서비스 확인
chkconfig --list php-fpm
php-fpm 0 : off 1 : off 2 : off 3 : off 4 : off 5 : off 6 : off
서비스 등록
chkconfig php-fpm on

PHP-FPM 설정

글로벌과 수영장 설정으로 나눈다. 많은 옵션이 있지만, 아래와 같이 짧게 설정해도 문제는 없습니다. FastCGI 프로세스는 고정 (static)으로 설정을 권장합니다. 
Apache-1.3의 초기 버전에서 FastCGI를 사용해 보았습니다 만, 동적 (dynamic)에서의 설정은 다양한 문제가 발생 한 경험이 있습니다. FastCGI 프로세스는 기다리는 과정이기 때문에 메모리 누수를주의해야합니다. PHP-FPM에서 요청의 최대 수 (pm.max_requests)를 설정하고 있으면 자동으로 자식 프로세스를 재시작 해주는 기능이있어, 메모리 누수를 방지합니다. 메모리의 상황을 확인하면서 고정 (static)으로 시작上げる子프로세스 수를 결정합니다. 
설정시주의해야 할 것은, 기본적으로 생성 된 소켓 파일은 apache 또는 nginx 권한에 액세스 할 수 없기 때문에 listen.mode에서 권한을 0666으로해야합니다. 2G 메모리 머신에서 프로세스 수를 100으로해도 문제없이 동작 확인했습니다. 사이트에 따라 다르므로 HTOP를 설치하고 메모리 사용량을 보면서 조정합니다. 뿌뿌로세스 수 고정 (static)의 설정은 일단로드되면 고정 메모리를 확보합니다. 동적 (dynamic)의 설정은 메모리 사용량이 설정 범위 내에서 액세스 수에 따라 달라집니다.

php-fpm.conf 설정
mkdir /etc/fpm.d
rm -f /etc/php-fpm.conf
전역 설정
cat > "/etc/php-fpm.conf" <<EOF
[global]
pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = notice
daemonize = yes
include=/etc/fpm.d/*.conf
EOF
풀 설정 (Apache 검증 권한)

Apache의 경우 아래의 설정으로 전환 확인합니다.

cat > "/etc/fpm.d/www.conf" <<'EOF'
[apache]
user = apache
group = apache
listen = /var/run/php-fpm.sock
listen.mode = 0666
pm = static
pm.max_children = 100
pm.max_requests = 1000
security.limit_extensions = .php .fphp .html .htm
EOF
풀 설정 (Nginx 검증 권한)

Nginx의 경우 아래의 설정으로 전환 확인합니다.

cat > "/etc/fpm.d/www.conf" <<'EOF'
[nginx]
user = nginx
group = nginx
listen = /var/run/php-fpm.sock
listen.mode = 0666
pm = static
pm.max_children = 100
pm.max_requests = 1000
security.limit_extensions = .php .fphp .html .htm
EOF
php 동작 테스트 파일 작성
cat > "/var/www/html/info_test.php" <<EOF
<?php
echo phpinfo();
?>
EOF

Nginx 컴파일 구축

nginx의 의존성에있는 라이브러리 설치
yum -y install GeoIP-devel.x86_64
yum -y install bxslt-devel.x86_64
yum -y install perl-ExtUtils-Embed.x86_64
yum -y install pcre-devel.x86_64
RPM-GPG-KEY 가져 오기
rpm --import http://mirror.centos.org/centos/6.5/os/x86_64/RPM-GPG-KEY-CentOS-6
Nginx의 최신 안정 버전 설치
rpm -i http://nginx.org/packages/centos/6/x86_64/RPMS/nginx-1.6.0-1.el6.ngx.x86_64.rpm
RPM 설치 디렉토리 확인
rpm -ql nginx
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/conf.d/example_ssl.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/rc.d/init.d/nginx
/etc/sysconfig/nginx
/usr/sbin/nginx
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx
/var/log/nginx

RPM으로 설치 한 이유는 각종 설정 파일을 자동으로 배치하는 것입니다. 후 소스에서 다운로드하여 Google 개발 오픈 소스 "ngx_pagespeed"을 지원하도록 따로 컴파일한 실행파일을 바꿉니다. "/usr/sbin/nginx"

Nginx 및 소스 다운로드
cd /opt/src
wget -q http://nginx.org/download/nginx-1.6.0.tar.gz
tar zxvf nginx-1.6.0.tar.gz

wget -q https://github.com/pagespeed/ngx_pagespeed/archive/v1.8.31.4-beta.zip -O ngx_pagespeed-1.8.31.4-beta.zip
unzip ngx_pagespeed-1.8.31.4-beta.zip

cd ngx_pagespeed-1.8.31.4-beta/
wget -q https://dl.google.com/dl/page-speed/psol/1.8.31.4.tar.gz
tar -xzvf 1.8.31.4.tar.gz
컴파일 설정

컴파일 옵션 확인은 기존 RPM으로 설치되어있는 것과 동일한 구성하기 위해 "nginx -V"명령으로 확인 pgespeed 모듈을 마지막으로 추가해야합니다.

cd /opt/src/nginx-1.6.0
./configure --prefix=/etc/nginx \
    --sbin-path=/usr/sbin/nginx \
    --conf-path=/etc/nginx/nginx.conf \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log \
    --pid-path=/var/run/nginx.pid \
    --lock-path=/var/run/nginx.lock \
    --http-client-body-temp-path=/var/cache/nginx/client_temp \
    --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
    --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
    --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
    --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
    --user=nginx --group=nginx \
    --with-http_ssl_module \
    --with-http_realip_module \
    --with-http_addition_module \
    --with-http_sub_module \
    --with-http_dav_module \
    --with-http_flv_module \
    --with-http_mp4_module \
    --with-http_gunzip_module \
    --with-http_gzip_static_module \
    --with-http_random_index_module \
    --with-http_secure_link_module \
    --with-http_stub_status_module \
    --with-http_auth_request_module \
    --with-http_xslt_module \
    --with-http_image_filter_module \
    --with-http_degradation_module \
    --with-mail \
    --with-mail_ssl_module \
    --with-file-aio \
    --with-ipv6 \
    --with-http_spdy_module \
    --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' \
    --with-ld-opt=' -Wl,-E' \
    --add-module=/opt/src/ngx_pagespeed-1.8.31.4-beta
컴파일
make -j10
기존 바이너리 교체
\cp objs/nginx /usr/sbin/nginx

Nginx 설정 (검증을위한 임시 설정)

Nginx 기본 설정

worker_processes CPU의 코어 수를 설정합니다.

기존 설정 백업
\cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf_backup
설정 파일 덮어 쓰기
cat > "/etc/nginx/nginx.conf"<< 'EOF'
user  nginx;
worker_processes  3;

error_log  /var/log/nginx/error.log warn;
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;
    tcp_nopush      on;

    keepalive_requests 100;
    keepalive_timeout 10;

    gzip  on;
    gzip_static on;
    gzip_comp_level 2;
    gzip_buffers 64 8k;
    gzip_min_length 1100;
    gzip_types        text/plain 
                      text/xml 
                      text/css 
                      application/xml 
                      application/xhtml+xml 
                      application/rss+xml 
                      application/atom_xml 
                      application/javascript 
                      application/x-javascript 
                      application/x-httpd-php;
    gzip_disable      "MSIE [1-6]\.";
    gzip_disable      "Mozilla/4";
    gzip_vary  on;
    gzip_proxied      any;
    gzip_http_version 1.1;

    server_tokens off;

    include /etc/nginx/conf.d/*.conf;

}
EOF
Nginx 서버 설정

기존 Apache 벤치 마크 디렉토리를 그대로 설정하고 벤치마킹을 실시합니다.

\cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf_backup

cat > "/etc/nginx/conf.d/default.conf" <<'EOF'
server {
    listen       80;
    server_name  localhost;

    location / {
        root   /var/www/html/;
        index  index.php;
        try_files $uri $uri/ /index.php?$uri&$args;
    }

    location ~ \.php$ {
        root           /var/www/html/;
        fastcgi_pass   unix:/var/run/php-fpm.sock;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  REMOTE_ADDR $remote_addr;
        fastcgi_param  REMOTE_PORT $remote_port;
        fastcgi_param  SERVER_ADDR $server_addr;
        fastcgi_param  SERVER_PORT $server_port;
        fastcgi_param  SERVER_NAME $server_name;
        fastcgi_param  CONTENT_TYPE $content_type;
        fastcgi_param  CONTENT_LENGTH $content_length;
        fastcgi_param  QUERY_STRING $query_string;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  REQUEST_METHOD $request_method;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param  SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param  REQUEST_URI $request_uri;
        fastcgi_param  DOCUMENT_URI $document_uri;
        fastcgi_param  DOCUMENT_ROOT $document_root;
        fastcgi_param  SERVER_PROTOCOL $server_protocol;
        fastcgi_param  GATEWAY_INTERFACE CGI/1.1;
        fastcgi_param  SERVER_SOFTWARE nginx/$nginx_version;
        fastcgi_param  HTTPS $https;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 256 16k; #4096k total
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
        fastcgi_max_temp_file_size 0; #disable buffering to disk
        client_max_body_size 0; #Allow large uploads
    }
}
EOF

Apache와 Nginx의 성능 검증 결과

nginx(woker) + php-fpm ⇒ 685.07 [#/sec]
apache(worker) + php-fpm ⇒ 594.79 [#/sec]
apache(prefork) + php-fpm ⇒ 560.84 [#/sec]
apache(prefork) + mod_php ⇒ 509.72 [#/sec]

위 결과는 환경이나 이용 상황에 따라 다를 수 있지만 대체로 "nginx (woker) + php-fpm"의 구성이 가장 좋은 성능이 나옵니다.

서버의 대역폭 검증 (TCP 처리량)

이 검사는 서버 2 대가 필요합니다. 로컬 또는 광역 네트워크에서도 확인할 수 있습니다. 서버 측의 방화벽을 해제해야합니다. 기본 포트는 5201입니다. 다음 도구를 모두 설치하고 확인합니다. 만일 서버의 IP를 "192.168.1.3/192.168.1.4"로 설정합니다. 이 검증은 AWS 또는 VPS 환경에서 DB 연결을 할 때 네트워크에 병목 현상이 없는지를 확인하기 위해서입니다. 또한 역방향 프록시 서버를 설정하여 운용 할 때 개별 서버에서 성능이 나오지도 네트워크에 병목 현상이 있고, 성능이 오르지 않는 경우가 있으므로 반드시 확인하여보십시오.

ym install -y iperf3
192.168.1.3:server

포트를 변경하는 경우에는 "- p 8080"과 같이 추가합니다.

iperf3 -s
192.168.1.4:client

서버 측의 포트가 기본 포트와 다른 경우는 "-p 8080"과 같이 추가합니다.

iperf3 -c 192.168.1.3