2015. 4. 26. 01:12

Apache


- 아파치 파일구조

· conf.d/아파치 전역에서 사용되는 잡다한 설정들

· apache2.conf기존 httpd.conf의 내용 및 sites-enabled, mods-enabled 파일들을 include하도록 하는 부분이 들어있다.

· httpd.conf아파치 1.x 버전 대와의 호환성 때문에 남아있다.

· sites-available/virtual host 설정을 보관한다.

· sites-enabled/sites-available로 symbolic link를 걸어 실제 사용하는 사이트들만 활성화한다. (여기에 링크가 존재해야만 아파치가 인식한다)

· mods-available/ 확장 모듈들 불러오기(*.load) 및 관련 설정(*.conf)들이 들어있다.

· mods-enabled/ sites-enabled와 마찬가지로 여기에 symbolic link가 걸려있어야 실제로 모듈이 로딩된다.

· ports.conf웹서버의 포트를 설정한다.

- 아파치 설정파일

# vim /etc/apache2/apache2.conf

--------------------------------------------------------------------

### Section 1: Global Environment// 아파치 전체적인 영향을 미치는 설정 부분

#

ServerRoot "/etc/apache2"// 아파치 루트 디렉토리 설정파일 로그파일 등이 존재

하는 곳 경로 마지막에 /를 붙혀서는 안됨

PidFile ${APACHE_PID_FILE}// 아파치 프로세서가 시작될 때 자신의 프로세서번호 (PID)를 기록하는 파일

Timeout 300// 클라이언트와 서버와 연결 후 둘 사이에 요청 이나

메시지가 발생 하지 않을 때 접속을 끊을 시간설정

KeepAlive On// 아파치 특정 프로세서가 특정 사용자의 지속적인 요청 을 계속 해서 처리 할 것인가 설정

MaxKeepAliveRequests 100// 한 프로세서가 이 옵션에 적힌 요청의 횟수만큼 지속 적인 요청을 처리(0으로 설정해두면 무한)

KeepAliveTimeout 15// 특정 클라이언트와 특정 프로세서가 처리 중 일 때 프로세서가 클라이언트의 다음 요청을 기다리는 시간

<IfModule mpm_prefork_module>

StartServers5// 기본 자식프로세스 개수(시작 시 띄울 프로세스 개수)

MinSpareServers5// 프로세스가 옵션보다 작으면 옵션 만큼 될 때 까지 프 로세스 생성

MaxSpareServers10// 프로세스가 옵션보다 많으면 옵션 만큼 될 때 까지 프 로세스 삭제

MaxClients150// 서버 접근 가능한 클라이언트 최대 개수

MaxRequestsPerChild0// 자식 프로세스가 처리 가능한 요청 개수 이 값 만큼 요청 받으면 자식 프로세스 죽음

</IfModule>

<IfModule mpm_worker_module>

StartServers2// 처음에 실행될 프로세스의 개수

Maxclients150// 동시 연결 가능한 클라이언트의 최대 개수

MinSpareThreads25// 새로운 클라이언트를 바로 처리하기 위해 대기하고 있 는 최소한의 스레드 수

MaxSpareThreads75// 새로운 클라이언트를 바로 처리하기 위해 대기하고 있 는 최대한의 스레드 수

ThreadsPerChild25// 하나의 자식프로세서가 계속 가질 수 있는 스레드 수

MaxRequestsPerchild0// 자식프로세서가 서비스할 수 있는 최대 요청 개수

</IfModule>

User apache// 요청을 대답하기 위하여 서버에 의해 사용되는 사용자 아이디를 지정

Group apache// 서버가 요청을 대답하는 그룹을 지정

AccessFileName .htaccess//

<Files ~ "^\.ht">// ht로 시작하는 모든 파일을 접근을 금지 시킴

Order allow,deny

Deny from all

</Files>

DefaultType text/plain// 파일 확장자를 통해 MIME형식을 알 수 없을 때 기본 적으로 쓸 MIME타입 지정

HostnameLookups Off// 클라이언트의 IP,이름을 기록할건지 off 경우 IP 저장 on 의 경우 이름으로 저장

ErrorLog /var/log/apache2/error.log

LogLevel warn// 로그파일의 저장 형식지정 그 종류로는 warn, debug, info, notice, crit, alert

Include /etc/apache2/mods-enabled/*.load

Include /etc/apache2/mods-enabled/*.conf

Include /etc/apache2/httpd.conf

Include /etc/apache2/ports.conf

LogFormat “%v:%p...” vhost_combined// CustomLog에서 사용할 형식에 대한 지정

LogFormat "%h %l..." combined

LogFormat "%h %l..." common

LogFormat "%{Re...." referer

LogFormat "%{Use.." agent

CustomLog /var/log.. vhost_combined// 로그파일의 위치와 형식 앞의 /var....가 파일 위치고 한 칸 띄우고 vhost_com...가 형식임

Include /etc/apache2/conf.d/

Include /etc/apache2/sites-enabled/

--------------------------------------------------------------------

# vim /etc/apache2/conf.d/charset

--------------------------------------------------------------------

AddDefaultCharset UTF-8// 웹서버 로케일 설정

--------------------------------------------------------------------

# vim /etc/apache2/conf.d/security

--------------------------------------------------------------------

ServerTokens Full// 아파치의 HTTP로서 응답할 헤드를 설정 종류로는

Prod : Product Only의 약어로 웹서버의 종류만 출력

Min : 웹서버의 종류와 버전을 출력

OS : 웹서버의 종류와 버전, 운영체제의 종류를 출력

Full : 웹서버의 종류,버전,운영체제,설치된 모듈 출력

ServerSignature On// On설정시 웹서버의 에러문서에서 추가적 정보를 출력

TraceEnable On// Trace메소드(client가 송신한 리퀘스트를 그대로 반환 하는 것)의 온・오프를 설정하는 옵션

--------------------------------------------------------------------

# vim /etc/apache2/sites-available/default

--------------------------------------------------------------------

<VirtualHost *:80>

ServerAdmin webmaster@localhost// 웹서버 관리자 e-mail 주소

DocumentRoot /var/www// 웹페이지 파일 들이 존재할 디렉토리

<Directory />

Options FollowsymLinks

AllowOverride None

</Directory>

<Directory /var/www/>

Options Indexes FollowSymLinks MultiViews

AllowOverride None

Order allow,deny

allow from all

</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/// 가상 디렉토리를 설정 가상도메인이 skill.com 이라면 skill.com/doc/cgi-bin/lin 을 입력하면 /usr/lib/cgi-bin/lin 스크립트를 실행

.

.

ErrorLog /var/log/apache2/error.log// 웹 에러 로그 파일 위치

LogLevel warn// 로그 레벨 설정

CustomLog /var/log/apache2/access.log combined// 웹 로그 파일 위치

Alias /doc/ "/usr/share/doc/"// 가상 디렉토리를 설정 가상도메인이 skill.com 이라면 skill.com/doc을 /usr/share/doc 으로 연결되게 하는 옵션 skill.com/doc/sea.jpg를 입력하면 /usr/share/doc/sea.jpg를 실행

</VirtualHost>

--------------------------------------------------------------------

- 아파치 가상호스트 실습

※ 전제 : 서버 IP는 192.168.0.1이고 이 서버에서 skill.com, www.skill.com order.skill.com의 DNS가 설정되어 있으며 192.168.0.1로 매핑되어 있음, 그리고 서버에는 /web, /www, /order 디렉토리가 생성되어 있고 각 폴더의 웹문서가 작성되어 있음

· skill.com, www.skill.com, order.skill.com 웹 사이트 만들기 실습

# vim /etc/apache2/apache2.conf

--------------------------------------------------------------------

ServerRoot "/etc/apache2"

LockFile /var/lock/apache2/accept.lock

PidFile ${APACHE_PID_FILE}

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 15

<IfModule mpm_prefo가_module>

StartServers5

MinSpareServers5

MaxSpareServers10

MaxClients150

MaxRequestsPerChild0

</IfModule>

<IfModule mpm_worker_module>

StartsServers2

MaxClients150

MinSpareThreads25

MaxSpareThreads75

ThreadsPerChild25

MaxRequestsPerChild0

User ${APACHE_RUN_USER}

Group ${APACHE_RUN_GROUP}

AccessFileName .htaccess

<Files ~"^\.ht">

Order allow,deny

Deny from all

</Files>

DefaultType text/plain

HostnameLookups Off

ErrorLog /var/log/apache2/error.log

LogLevel warn

Include /etc/apache2/httpd.conf

Include /etc/apache2/ports.conf

LogFormat “%v:%p...” vhost_combined

LogFormat "%h %l..." combined

LogFormat "%h %l..." common

LogFormat "%{Re...." referer

LogFormat "%{Use.." agent

CustomLog /var/log/apache2/other_vhosts_access.log vhost_combined

Include /etc/apache2/conf.d/

Include /etc/apache2/sites-enabled/

DocumentRoot /web// 웹 파일들이 위치한 디렉토리 설정

DirectoryIndex index.html// 웹에 보여줄 웹 파일이름

ServerName skill.com// 기본 서버 네임 설정

NameVirtualHost 192.168.0.1:80// 네임기반 가상호스트 운영

--------------------------------------------------------------------

# vim /etc/apache2/sites-available/default

--------------------------------------------------------------------

※ 이 파일의 기본값 세팅 되어 있는 것 모두 삭제

<VirtualHost 192.168.0.1:80>

ServerName skill.com

</VirtualHost>

<VirtualHost 192.168.0.1:80>// 192.168.0.1:80에 대해 가상 호스트 설정 시작

ServerAdmin root@skill.com// 관리자 메일 주소

ServerName www.skill.com// 서버 이름

DocumentRoot /www// 웹 파일들이 위치한 디렉토리 설정

DirectoryIndex www.html// 웹에 보여줄 웹 파일이름

Errorlog log/wwwe_log// 에러 로그 파일 위치

Customlog log/wwwc_log common// 커스텀로그 파일 위치

</VirtualHost>// 가상호스트 설정 끝

<Virtualhost 192.168.0.1:80>

ServerAdmin root@skill.com

ServerName order.skill.com

Documentroot /order

ServerAlias ad.skill.com// order.skill.com을 ad.skill.com으로도 접속하게 설정

DirectoryIndex order.html

ErrorLog ordere_log

CustomLog orderc_log common

</VirtualHost>

--------------------------------------------------------------------

# vim /etc/apache2/ports.conf

--------------------------------------------------------------------

NameVirtualHost *:80// 이 행 삭제

--------------------------------------------------------------------

# /etc/init.d/apache2 restart

- 아파치 한글 설정

※보통은 기본으로 한글설

정이 자동으로 되나, 만약 안 되는 경우

한글로 만든 웹 파일을 DocumentRoot로 지정된 디렉토리에 옴겨 주고, 웹파일 이름을 DirectoryIndex에 적어준다.

# Vim /etc/apache2/conf.d/charset

--------------------------------------------------------------------

AddDefaultCharset EUC-KR// 이렇게 바꿔줌

--------------------------------------------------------------------

# /etc/init.d/apache2 restart

- 리다이렉트 설정

· ad.skill.com/v2.html을 www.skill.com으로 리다이렉트 할 때

# vim /etc/apache2/sites-available/default

--------------------------------------------------------------------

.

.

<Virtualhost 192.168.0.1:80>

ServerAdmin root@skill.com

ServerName ad.skill.com

Redirect /v2.html http://www.skill.com

</Virtualhost>

--------------------------------------------------------------------

· ad.skill.com을 www.skill.com으로 리다이렉트 할 때

# vim /etc/apache2/sites-available/default

--------------------------------------------------------------------

.

.

<Virtualhost 192.168.0.1:80>

ServerAdmin root@skill.com

ServerName ad.skill.com

Redirect / http://www.skill.com

</Virtualhost>

--------------------------------------------------------------------

- php 연동

php 설치를 함

# ln -s /etc/apache2/mods-available/php5.* /etc/apache2/mods-enabled/

-> php모듈 적재

# vim /etc/apache2/apache2.conf

--------------------------------------------------------------------

.

.

DocumentRoot /web// 웹 문서가 위치할 디렉터리 설정

DirectoryIndex index.php// php로 작성한 웹 문서 적어줌

--------------------------------------------------------------------

# vim /web/index.php

--------------------------------------------------------------------

<?// php언어로 문서를 작성

echo "phptest";

phpinfo();

?>

--------------------------------------------------------------------

- 인증을 통한 접속

·.htaccess 파일을 사용한 사용자 인증

# vim /etc/apache2/sites-available/default

--------------------------------------------------------------------

<VirtualHost 192.168.0.1:80>

ServerAdmin root@skill.com

ServerName www.skill.com

DocumentRoot /www

<Directory /www>// 해당도메인으로 접속될때 /www 디렉토리로 접속하는 것이기 때문에 /www에 대한 권한을 제한

AllowOverride Authconfig// .htaccess파일을 사용할건지 말건지

</Directory>

DirectoryIndex www.html

Errorlog /log/wwwe_log

Customlog /log/wwwc_log common

</VirtualHost>

--------------------------------------------------------------------

# vim /www/.htaccess

--------------------------------------------------------------------

AuthName "access deny login// 인증창에 뜰 메시지

AuthType Basic// 인증 방법

AuthUserFile /www/.htpasswd// 인증을 허가할 유저가 담겨있는 파일

AuthGroupFile /dev/null// 사용자인증이니 사용하지 않음, 보기 같이 설정해야함

<Limit GET POST>

require valid-user// 파일에 지정된 사용자들만 접근 허용

#require user kim// 지정된 유저만 접근허용(kim만 접근가능)

</Limit>

--------------------------------------------------------------------

# htpasswd -c /www/.htpasswdlee// .htpasswd파일을 생성하며 lee사용자를 인증 허가에 등록시킴

# htpasswd /www/.htpasswd kim// 파일은 생성하지 않고 사용자만 추가

# /etc/init.d/apache2 restart

·.htaccess 파일을 사용한 그룹 인증

# vim /etc/apache2/sites-available/default

--------------------------------------------------------------------

<VirtualHost 192.168.0.1:80>

ServerAdmin root@skill.com

ServerName www.skill.com

DocumentRoot /www

<Directory /www>// 해당도메인으로 접속될때 /www 디렉토리로 접속하는 것이기 때문에 /www에 대한 권한을 제한

AllowOverride Authconfig// .htaccess파일을 사용할건지 말건지

</Directory>

DirectoryIndex www.html

Errorlog /log/wwwe_log

Customlog /log/wwwc_log common

</VirtualHost>

--------------------------------------------------------------------

# vim /www/.htaccess

--------------------------------------------------------------------

AuthName "access deny login// 인증창에 뜰 메시지

AuthType Basic// 인증 방법

AuthUserFile /www/.htpasswd// 유저 목록파일

AuthGroupFile /www/.htgroup// 그룹 정보가 담겨 있는 파일

<Limit GET POST>

require group school// 지정된 그룹만 접근 허용

</Limit>

--------------------------------------------------------------------

# vim /www/.htgroup

--------------------------------------------------------------------

<그룹이름>: <사용자> <사용자> 형식으로 적어줌

school: lee kim// 여기 명시된 사용자는 .htpasswd파일에 있어야 함

--------------------------------------------------------------------

# htpasswd -c /www/.htpasswd lee

# htpasswd /www/.htpasswd kim

# /etc/init.d/apache2 restart

·.htaccess 파일을 사용하지 않은 사용자 인증

# vim /etc/apache2/sites-available/default

--------------------------------------------------------------------

<VirtualHost 192.168.0.1:80>

ServerAdmin root@skill.com

ServerName www.skill.com

DocumentRoot /www

<Directory /www>

AllowOverride none// .htaccess파일을 사용할건지 말건지

AuthType basic

AuthName 'login access failed'

AuthUserFile /www/.htpasswd

AuthGroupFile /dev/null

require valid-user

</Directory>

DirectoryIndex www.html

Errorlog /log/wwwe_log

Customlog /log/wwwc_log common

</VirtualHost>

--------------------------------------------------------------------

# htpasswd -c /www/.htpasswd lee

# htpasswd /www/.htpasswd kim

# /etc/init.d/apache2 restart

·.htaccess 파일을 사용하지 않은 그룹 인증

# vim /etc/apache2/sites-available/default

--------------------------------------------------------------------

<VirtualHost 192.168.0.1:80>

ServerAdmin root@skill.com

ServerName www.skill.com

DocumentRoot /www

<Directory /www>

AllowOverride none// .htaccess파일을 사용할건지 말건지

AuthType basic

AuthName 'login access failed'

AuthUserFile /www/.htpasswd

AuthGroupFile /www/.htgroup

require group absol

</Directory>

DirectoryIndex www.html

Errorlog /log/wwwe_log

Customlog /log/wwwc_log common

</VirtualHost>

--------------------------------------------------------------------

# vim /www/.htgroup

--------------------------------------------------------------------

absol: sin gun// 여기 나열된 사용자는 .htpasswd에 등록 되어 있어야함.

--------------------------------------------------------------------

# htpasswd -c /www/.htpasswd sin

# htpasswd /www/.htpasswd gun

# /etc/init.d/apache2 restart

- 아파치 모니터링

# vim /etc/apache2/sites-available/default

--------------------------------------------------------------------

<VirtualHost 192.168.0.1:80>

ServerAdmin root@skill.com

ServerName www.skill.com

DocumentRoot /www

DirectoryIndex www.html

ErrorLog /log/wwwe_log

CustomLog /log/wwwc_log common

<Location /sk-mo>// www.skill.com/sk-mo로 접속하면 모니터링이 보이게 설정

SetHandler server-status

Order deny,allow

Allow from all

</Location>

--------------------------------------------------------------------

'OPS > LInux' 카테고리의 다른 글

user management on debian  (0) 2015.04.26
grub  (0) 2015.04.26
bind9  (0) 2015.04.26
dhcp  (0) 2015.04.26
fdisk  (0) 2015.04.26
Posted by 배주혁