Action disabled: source

Apache

웹서버에서 받는 여러 요청을 MPM (Multi Processing Module 다중 처리 모듈)에서 처리하는데 Apache2 에서는 Prefork와 worker 두 가지 방식이 있다.

보통 아파치를 사용하는 경우 Prefork 모드를 이용하여 설치를 많이 한다. 우분투의 경우도 11.10까지 apt-get 로 설치를 하게되면 이 방식으로 설치되어 오다 12.04 부터 worker가 기본으로 변경되었다.

리눅스에서 보면 부모 프로세스 , 자식 프로세스 라는 말이 있다. 즉 아파치 웹 서버가 받아들이는 요청을 처리하기 위해 자식 프로세스에게 분배하는 방식이다.

Prefork MPM uses multiple child processes with one thread each and each process handles one connection at a time.

Worker MPM uses multiple child processes with many threads each. Each thread handles one connection at a time.

On most of the systems, speed of both the MPMs is comparable but prefork uses more memory than worker.

자신의 웹서버 방식 확인은 콘솔에서 apache2 -l 혹은 httpd -l 해보면 버전과 함께 사용된 모듈파일들이 나오는데 prefock.c 가 있다면 prefo ck이고 worker.c가 있다면 worker이다.

서버에 어떤 MPM이 설치되어 있는지 보려면

apache2 -V | grep MPM

Prefork

실행중인 프로세스를 메모리 영역까지 복제하여 실행한다. 프로세스가 소비하는 메모리가 많다. 이것 때문에 사람들이 엔진엑스보다 아파치가 메모리를 많이 먹는다 라고들 한다. 메모리는 많이 먹는 대신 응답 프로세스를 미리 띄어 놓고 클라이언트가 요청을 하면 자식 프로세스가 반응하게 된다.

성능향상법(영문)

Worker

일반적으로 멀티 CPU인 서버에서의 성능이 뛰어나다. 요즈음 쿼드 코어다 헥사코어다 해서 CPU들의 코어가 2개 이상인 시스템이 많은데 요청을 쓰레드(thread) 단위로 처리하며 최대 64개의 쓰레드로 할 수 있다. 지정된 만큼의 프로세스와 각 쓰레드를 준비하여 클라이언트의 요청을 받아 들이는 방식이다. 대신 Prefork보다 아주 적은 메모리를 사용하게 된다.

On high traffic websites worker is preferable because of low memory usage as comparison to prefork MPM but prefork is more safe if you are using libraries which are not thread safe.

For example you cannot use mod_php(not thread safe) with worker MPM but can use with prefork.

설정

Listen port

  1. /etc/apache2/ports.confListen 80Listen 8888 등으로 수정
  2. /etc/apache2/sites-enables/000-default 파일을 열어서 제일 윗줄에서 :80 을 원하는 포트 번호로 수정

DOS 공격 방어 모듈

[evasive 모듈 설치]

   apt-get install libapache2-mod-evasive

설치가 완료되면 자동으로 모듈이 올라가고 아파치가 재시작 됩니다. 모듈이 안올라갈 경우 심볼링크로 링크를 걸어 줍니다.

심볼링크 생성

   cd /etc/apache2/mods-enabled
   ln -s ../mods-available/mod-evasive.load ./mod-evasive.load

[apache2.conf 맨 아래 추가] <IfModule mod_evasive20.c>

  DOSHashTableSize  3097
  DOSPageCount        5
  DOSSiteCount          50
  DOSPageInterval      1
  DOSSiteInterval        1
  DOSBlockingPeriod  30
  DOSLogDir              "/var/log/mod_evasive.log"
  DOSWhitelist            127.0.0.1

</IfModule>

추가 완료후 /etc/init.d/apache2 restart 로 아파치 재시작

Rewrite module 활성화

  • 일단 모듈이 올라가있는지 확인..(phpinfo)
  • /usr/local/apache/conf/httpd.conf 수정
  - rewriteEngine On
<IfModule mod_rewrite.c>
rewriteEngine On
</IfModule>
  • 다음을 찾아서 AllowOverride All로 수정
<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    #Deny from all
</Directory>
  • 아파치 재시작

아파치 모드 추가

아파치 mod_expires 모듈에 관해 알아 보았는데 우분투는 sudo a2enmod expires 하고 아파치 재시작하면 사용할 수 있다(역시 편한 우분투)

.htaccess에 추가.

ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/png A2592000

역링크