Server & OS

우분투 Apache 이해

페이지 정보

본문

출처 : http://webdir.tistory.com/196

 

 

우분투는 일반적인 리눅스 배포판들과 다른 구조를 하고 있다. 데비안 계열의 특징인듯...

 

 

 

/etc/apache2 : 설정파일 루트위치 

설정파일들이 이 디렉토리 밑에 위치하고 있다.

 

/etc/apache2/apache2.conf : 기본설정 파일 

다른 배포판에서 httpd.conf 를 기본 설정파일로 사용하고 있는데 우분투에서는 apache2.conf 를 사용한다.

 

/etc/apache2/conf.d : 고급설정 파일

다 른 배포판에서 httpd.conf 파일 하나에 설정되어 있던 문자셋과 에러메시지, 보안과 관련된 설정등을 따로 따로 분리하여 conf.d 디렉토리밑에서 설정하고 있다. 또한 사용자가 설치하게 되는 Apache와 관련된 애플리케이션들의 설정파일들도 위치하게 된다.

 

 /etc/apache2/envvars : apache2ctl 환경설정 파일

 

/etc/apache2/httpd.conf : 사용자의 특정 설정 파일

역사적으로 httpd.conf 가 기본설정 파일이였는데 지금은 빈파일이다.

사용자가 특정 설정을 부여해서 사용할 수 잇다.

 

/etc/apache2/magic

파일의 시작값(magic number) 데이터베이스. 이 값에 기반해 전송하는 파일의 MIME Type을 결정한다.

가급적 수정하지 말 것.

 

 

/etc/apache2/mods-available

사용가능한 Apache 모듈을 불러오는 곳

 

/etc/apache2/mods-enabled

위의 /etc/apache2/mods-available 의 모듈중에 사용할 모듈을 심볼릭 링크로 추가하여 실제 동작하게 만든다.

 

/etc/apache2/ports.conf

Apache 서버의 서비스 포트 설정으로 http 의 기본값 80 과 https 의 기본값 443, 가상호스트의 포트들을 설정할 수 있다.

 

/etc/apache2/sites-available

서버에서 운영할 사이트의 설정파일

 

/etc/apache2/sites-enabled

위의 /etc/apache2/sites-available 에서 설정한 파일을 심볼릭 링크로 추가하여 실제 운영에 사용할 설정파일들이다.

 

 

1. 기본 사이트 설정 사항 ( /etc/apache2/sites-available/default )

apache2 의 기본설정은 가상호스트 친화적이다.

기본적으로 VirtualHost 지시자에 의해 하나의 가상호스트가 설정되어 있고 하나의 사이트만을 운영할 계획이라면 이 가상호스트 설정이 기본적인 웹사이트가 된다.

/etc/apache2/sites-available/default 파일을 수정하여 사용하면 된다.

 

ServerAdmin 의 메일주소를 원하는 것으로 수정하고 다른 여러 다른 가상호스트에서 설정하지 않을 경우 대표메일 주소로 이용된다.

 

ServerName 이 지정되어 있지 않다.

이는 다른 가상호스트의 ServerName 과 매치되지 않는 모든 요청에 대하여 응답하게 된다.

이를 원하지 않는다면 ServerName 에 구입한 도메인을 추가한다.

 

ServerAlias 도 기본적으로 지정되어 있지 않지만 www 를 호스트명으로 이용하는 경우가 많으니 이를 추가해도 된다.

  

DocumentRoot 값은 /var/www 로 지정되어 잇는데 원한다면 이를 수정하여 사용할 수 있다.

 

<Directory> 지사자에 Option 항목에 Indexes 가 설정되어 있는데 이를 제거해서 파일리스트들이 출력되지 않게 할 수 있다.

<Directory /home/MyID/www/uzuro.com>

Option -Indexes FollowSymLinks MultiViews

 

2. 새로운 가상호스트 추가법

우선 default 파일을 복사해 원하는 파일명(사이트명)으로 변경한다.

새로운 사이트의 디렉토리를 생성하고 복사한 파일의 DocumentRoot의 경로를 설정한다.

 

a2ensite 유틸리티를 사용하여 추가한다.

$ sudo a2ensite mynewsite

$ sudo service apache2 restart

 

3. DirectoryIndex 설정

/etc/apache2/mods-available/dir.conf 에서 설정할 수 있으면 기본적으로 index.html, index.cgi, index.pl, index.php, index.xhtml, index.htm 이 설정되어 있다. 필요하다면 더 추가하면 된다.

위 파일들이 요청한 디렉토리에 없다면 <Directory> 지시자의 Option 값으로 Indexes가 설정되어 있을 경우 파일이 리스팅된다.

 

4. ErrorDocument 설정

/etc/apache2/conf.d/localized-error-pages 에서 설정할 수 있다.

 

5. Log 설정

Apache 의 기본 로그 파일은 /var/log/apache2/ 디렉토리에 access.log, error.log, other_vhosts_access.log 로 존재한다. 가상호스트 설정에서 ErrorLog 지시자나 CustomLog를 따로 설정하지 않는다면 위에 언급한 파일들에 로그가 저장되고 만약 가상호스트에서 설정사항을 주석처리하거나 삭제한다면 other_vhosts_access.log 파일에 생성된다.

 

여러개의 사이트를 운영할 계획이라면 각각의 홈디렉토리에 logs 디렉토리를 생성하여 그곳에 위치하는 방법을 많이 사용한다.

 

6. Apache 서비스를 재시작할때마다 에러메시지가 함께 나올텐데 기본으로 설정된 사이트의 ServerName이 존재하지 않아서이다. 이는 /etc/apache2/apach2.conf 에 ServerName localhost 와 같이 추가하면 된다. 

 

7. 새로운 모듈 추가

우분투는 기본적으로 동적으로 모듈을 불러오도록 컴파일되어 있다.

<IfModule> 블럭으로 둘러쌓아 특정한 모듈에 대한 지시를 할 수 있고 /etc/apache2/mods-enabled 에 등록하여 이를 사용할 수 있다.

/etc/apache2/mods-available 디렉토리에 존재하지 않는 모듈들은 apt-get등으로 설치한다.

 

$ sudo a2enmod ssl

$ sudo service apache2 restart

 

사용하지 않을 모듈은

$ sudo a2dismod ssl 과 같이 사용하고 apache 서비스 재시작

 

8. 리눅스 계정의 사용자들이 각각 홈디렉토리에서 웹사이트를 운영할때 설정

 - /home/UserID/public_html 의 구조를 생성한다.

$ mkdir public_html (이때 폴더 소유자는 그계정의 사용자ID임에 유의)

 

- 유저디렉토리 모듈 활성화

$ sudo a2enmod userdir.conf

$ sudo a2enmod userdir.load

$ sudo service apache2 restart

( 사용자들이 http://서버도메인(IP)/~UserID 로 접근이 가능하게 된다 )

 

- $ sudo vi /etc/apache2/mods-available/userdir.conf 의 설정내용을 알맞게 변경

 

- php의 모듈 사용자 디렉토리에 활성화

php 모듈의 기본 설정이 기본적으로 /home/*/public_html 상에서는 사용불가로 되어 있다.

$ sudo vi /etc/apache2/mod-available/php5.conf

<IfModule mod_userdir.c> 부분부터 끝나는 블록까지 주석처리한다.

 

8. HTTPS 설정

The mod_ssl module adds an important feature to the Apache2 server - the ability to encrypt communications. Thus, when your browser is communicating using SSL, the https:// prefix is used at the beginning of the Uniform Resource Locator (URL) in the browser navigation bar.

The mod_ssl module is available in apache2-common package. Execute the following command from a terminal prompt to enable the mod_sslmodule:

sudo a2enmod ssl

There is a default HTTPS configuration file in /etc/apache2/sites-available/default-ssl. In order for Apache2 to provide HTTPS, a certificateand key file are also needed. The default HTTPS configuration will use a certificate and key generated by the ssl-cert package. They are good for testing, but the auto-generated certificate and key should be replaced by a certificate specific to the site or server. For information on generating a key and obtaining a certificate see Certificates

To configure Apache2 for HTTPS, enter the following:

sudo a2ensite default-ssl

The directories /etc/ssl/certs and /etc/ssl/private are the default locations. If you install the certificate and key in another directory make sure to change SSLCertificateFile and SSLCertificateKeyFile appropriately.

With Apache2 now configured for HTTPS, restart the service to enable the new settings:

sudo service apache2 restart

Depending on how you obtained your certificate you may need to enter a passphrase when Apache2 starts.

You can access the secure server pages by typing https://your_hostname/url/ in your browser address bar.

For more than one user to be able to write to the same directory it will be necessary to grant write permission to a group they share in common. The following example grants shared write permission to /var/www to the group "webmasters".

sudo chgrp -R webmasters /var/www
sudo find /var/www -type d -exec chmod g=rwxs "{}" \;
sudo find /var/www -type f -exec chmod g=rws  "{}" \;

If access must be granted to more than one group per directory, enable Access Control Lists (ACLs).

 

참고 : https://help.ubuntu.com/12.04/serverguide/httpd.html

 

 

 

 

 

관련자료

등록된 댓글이 없습니다.
Today's proverb
살아 있는 동안 더 많이 감탄하세요. 가슴을 열고 보면 어디 감탄할 거리가 한두 가지입니까. 감탄할 거리가 있을때가 참을 것이 아니라 즉각 감탄해야 합니다. 가슴 두근거리고 놀라고 환호할때 우리의 행복은 곱으로 느껴집니다. (정채봉)