Apache | Apache 설치 | 설정 파일(http.conf)의 초기 설정하기

Apache에 대한 설정은 http.conf 파일에서 설정한다. Apache를 설치 한 후에 설치한 디렉터리이나 사용하는 포트 번호에 맞게 설정 파일을 변경을 해야 한다. 여기에서는 Apache 설치 직후에 실시 초기 설정에 대해 설명한다.

설치 디렉터리 수정

Apache 설정 파일인 http.conf 파일은 설치 디렉터리에서 “/Apache24/conf/“에 들어 있다.

MacOS은 /etc/apache2/httpd.conf 에 있다.

수정하기 전에 http.conf 파일을 만약을 위해 복사하여 백업으로 따로 저장하도록 하자. (구지 할 필요가 없다고 생각된다면 안해도 된다.)

그러면 http.conf 파일을 편집하도록 하겠다. http.conf 파일은 텍스트 파일이므로 텍스트 편집기에서 열면 열린다. (예를 들면, 윈도우 메모장도 편집이 가능하다.)

먼저 파일에서 “ServerRoot“을 검색한다. 그러면 다음과 같이 작성되어 있는 것을 찾을 수 있다.

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path.  If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used.  If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
Define SRVROOT "c:/Apache24"

ServerRoot "${SRVROOT}"

ServerRoot에 Apache 서버의 디렉터리를 설정한다. 기본적으로 “c:/Apache24"로 되어 있는 부분을 실제로 Apache를 설치한 디렉터리로 변경하면 된다. 구체적으로는 SRVROOT 변수에 설치한 디렉터리 설정하고 있고, ServerRoot에 SRVROOT 변수를 사용하여 설정하고 있다. 여기에서는 다음과 같이 변경하였다.

Define SRVROOT "C:/apache/Apache24"

ServerRoot "${SRVROOT}"

위에서 설정한 SRVROOT 변수는 아래와 같이 다른 설정 부분에서 사용하여 동일한 디렉터리가 설정된다.

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "${SRVROOT}/htdocs"

<Directory "${SRVROOT}/htdocs">

 ...생략...

</Directory>
<IfModule alias_module>

 ...생략...

    #
    # ScriptAlias: This controls which directories contain server scripts. 
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the target directory are treated as applications and
    # run by the server when requested rather than as documents sent to the
    # client.  The same rules about trailing "/" apply to ScriptAlias
    # directives as to Alias.
    #
    ScriptAlias /cgi-bin/ "${SRVROOT}/cgi-bin/"

</IfModule>

#
# "${SRVROOT}/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "${SRVROOT}/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

포트 번호 설정

다음 포트 번호 설정을 확인한다. 파일에서 “Listen“을 검색한다.

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

Listen는 Apache가 어떤 포트 번호와 IP 주소를 listen 할 것인지를 설정한다. 일반적으로 Web 서버와 브라우저와의 통신은 80번 포트를 사용하여 실행되기에 기본 설정에도 80번이 설정되어 있다. 일반적으로 변경할 필요는 없지만, 여러 Web 서버가 동일한 서버 컴퓨터에서 실행하는 경우에는 포트 번호가 중복되지 않게 여기에서 설정을 변경하면 된다.

ServerName 설정

마지막으로 ServerName 설정이다. 설정 파일에서 “ServerName“을 검색한다.

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80

ServerName은 서버 자체를 나타내는 호스트명과 포트 번호를 설정한다. 초기 설정은 주석으로 되어 있고 설정하려면 “www.example.com:80"와 같이 호스트명 + 포트 번호로 설정한다. (포트 번호를 생략하면 서버에 요청을 할 수 있는 기본 포트 번호인 80을 사용한다.)

여기에서는 Apache는 로컬 환경에 설치되어 있기 때문에 ServerName 앞에 “#“을 제거하고 다음과 같이 변경하였다.

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost:80

설정 파일의 수정이 끝나면 설정 파일을 저장한다.




최종 수정 : 2019-12-10