DB,서버,OS 등

[Apache] port 추가하기. httpd vHosts

bryan.oh 2020. 12. 23. 00:52
반응형

Apache24 Virtual Host(vHosts) 설정

보통 8080 으로 쓰는데, 다른 포트를 추가하고 소스 디렉토리 설정 하는 방법입니다.

 

Apache 설정에서 vhosts conf 주석 해제하기.

{apache_home}/conf/httpd.conf 를 열어서 vhosts.conf 로 검색합니다.

아래 그림처럼 주석을 해제합니다.

Listen 부분을 찾아서 추가할 port 를 추가해줍니다.

8080은 기본으로 되어있었고 8090 을 추가하는 예제입니다.

 

{apache_home}/conf/extra/httpd-vhosts.conf 파일 수정

기본 예제로 입력되어있는 설정은 주석 치시고, 사용할 설정을 입력합니다.

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:8090>
    ServerAdmin com.bryan.oh@gmail.com
    DocumentRoot "C:/dev/admin"
    <Directory "C:/dev/admin">
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

C:\dev\admin 이라는 폴더가 존재해야 하고, 그 안에 소스 파일이 있어야 합니다.

일단 이 설정한 폴더 경로에 index.html 파일을 하나 만들고,
소스는 뭐 대충 hello 입력하고 저장하세요.

 

Apache 서비스 재시작

 

 

브라우저에서 확인

위에서 설정한 port 로 들어가 봅니다.

이렇게 해서 여러 사이트를 개발할 수 있습니다.

 

안된다면?

  • *.conf 파일의 내용에 오타가 있으면 아파치 서버가 재시작이 안됩니다. 오타 없는지 확인하세요.
  • 리눅스의 경우 폴더 403 오류가 발생할 수 있습니다. 폴더권한을 부여해보세요.
  • 위에서 설정한 경로에 index.html 외에 다른 파일을 사용할 것이라면, 예를들어 test.html 이면 주소창에 localhost:8090/test.html 로 써줘야겠죠. index.html 도 httpd.conf 에 기본 페이지로 설정했기때문에 나오는겁니다.

 

즐거운 개발인생~

 

 

 

728x90
반응형