스킬/개인서버

[아파치 서버] htdocs 가 아닌 폴더 또는 드라이브를 홈페이지 디렉토리로 설정(루트디렉토리 설정)

GET2 2023. 7. 7. 18:21
728x90
반응형

 

 

 

https://xe1.xpressengine.com/tip/19379495

 

Apache 서버운영에 쓸모있는 팁 몇가지 - 웹마스터 팁 - XpressEngine

http://pclab.cataegu.ac.kr/Server.html저의 졸작인 [초보자를 위한 Windows용 Apache2 + PHP + MySQL 설치] 강좌가 엄청난 조회수를 기록하고 있네요. 그림이 너무 많아서 내용은 이곳에 직접 올리지 못하고 제 홈

xe1.xpressengine.com

1서버/1홈페이지 운영중인 분들은 위 링크의 1번 글만 보셔도 됩니다.


이 게시글은 1서버/다중 홈페이지 운영중인 기준으로 설명을 드리기 위해 작성했습니다.

서버환경 : WAMP를 이용하여 아파치2서버와 마리아DB를 이용중입니다. 어쨋든 아파치2 서버 프로그램을 구동중이라면 모두 적용 가능한 방법입니다.

 

아파치2 서버의 홈페이지 루트디렉토리는 보통 이렇습니다.

C:\apache2\htdocs

사전에 설정된 루트 디렉토리 외 C:\homepage 또는 D:\webpage 등 폴더나 드라이브를 가상호스트로 설정한 후 접속해보면 아래와 같은 권한없음 화면이 나오죠.

 

Forbidden / You don't have permission to access this resource.

아파치 서버의 httpd.conf 파일에 루트디렉토리 추가와 httpd-vhosts.conf 에 가상 호스트 추가만 하면 문제없이 연결할 수 있습니다.

 


 

1. httpd.conf 파일을 수정해주세요.

httpd.conf 파일은 보통 "C:\apache2\conf"에 존재합니다.

 

해당 파일을 열면 아래 '원본'의 내용과 동일한 구문을 찾으실 수 있습니다. (Ctrl+F로 "Controls who can get stuff from this server."를 검색하면 빠르겠네요)

 

원본

#
# 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 "C:/Bitnami/wampstack-8.1.10-0/apache2/htdocs"
<Directory "C:/Bitnami/wampstack-8.1.10-0/apache2/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
	AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

위 원본의 </Directory> 바로 아래 칸에 아래의 구문을 추가하세요.

DocumentRoot "I:/server/" <-[드라이브 명:폴더 명]은 본인이 추가하고자 하는 서버상의 루트디렉토리로 기입해주세요.
<Directory "I:/server/"> <-[드라이브 명:폴더 명]은 본인이 추가하고자 하는 서버상의 루트디렉토리로 기입해주세요.

# htdocs외 폴더 또는 C: 드라이브 외 다른 드라이브(외장하드 등)를 다큐멘트 루트로 설정하기 위해 선언
DocumentRoot "I:/server/"
<Directory "I:/server/">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

httpd.conf 수정할 사항은 끝났습니다.

 


2.httpd-vhosts.conf 를 수정하겠습니다.

httpd-vhosts.conf 파일은 보통 "C:\apache2\conf\extra"에 존재합니다.

 

우선 80포트 블럭입니다.(SSL 비인증)

<VirtualHost *:80>
	ServerName 내홈페이지.com
	ServerAlias www.내홈페이지.com
	DocumentRoot "I:/server"
	ErrorLog "logs/내홈페이지-error.log"
	CustomLog "logs/내홈페이지-access.log" common
</VirtualHost>

 

그리고 443포트 블럭입니다. (SSL 인증)

<VirtualHost *:443>
	ServerName 내홈페이지.com
	ServerAlias www.내홈페이지.com
	DocumentRoot "I:/server"
	SSLEngine on
	SSLCertificateFile "C:/acmewin-SSL-pem/내홈페이지이름/내홈페이지이름.com-chain.pem"
	SSLCertificateKeyFile "C:/acmewin-SSL-pem/내홈페이지이름/내홈페이지이름.com-key.pem"
</VirtualHost>

 

80포트 블럭과 443포트 블럭을 httpd-vhosts.conf 에 추가하시고 아파치서버매니저를 재시작 꼭 해주세요.

 

 

 

 

 

728x90
반응형