IT/잡다구리

[Window+Apache] 로컬 커스텀도메인 설정 방법 , localhost customDomain

월공 2022. 12. 1. 14:01
728x90
300x250

로컬에서 작업중인 프로젝트에 커스텀 도메인 넣어서 하는법을 포스팅 한다.
아파치 같은 웹서버가 깔려있다는 가정하에 진행한다.

시작 하기전에 hosts 라는 놈이 무슨 일을 하는지 간략하게 설명하자면 여기다 ip 주소 선언하고 어떤 도메인이든 써놓으면 곧이 곧대로 들어가진다.
쉽게 말해서 내 로컬호스트에서 PHP 돌리고있고 hosts 파일에다가 naver.com  이라고 도메인 접속하면
찐 네이버가 아니라 내 로컬 컴퓨터의 PHP 사이트를 띄운다는 소리다.

여튼 hosts 파일 설정하는 방법은 별거 없다 메모장이나 텍스트 에디터 파일 "관리자 권한" 으로 열어서 수정하면된다.

경로 : C:\Windows\System32\drivers\etc

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost

127.0.0.1	localhost
::1	localhost
127.0.0.1	test.tw
::1	test.tw
127.0.0.1	shop.test.tw
::1	test.hangloo.tw

# 127.0.0.1 naver.com

만약에 위처럼 서브 도메인(shop)으로 추가해서 작업하고싶으면 IP 는 똑같이 두되 , apache httpd-vhosts 파일에서 수정을 해줘야한다.
나는 xampp 를 깔아서 경로가 이런것이고 혹 xampp 가 아닌 별도로 아파치를 설치했다면 설치한 경로로 찾아가서 conf 폴더 뒤져보면 된다.

경로 : C:\xampp\apache\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.

#
# Use name-based virtual hosting.
#
##NameVirtualHost *:80
#
# 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 *:80>
    ##ServerAdmin webmaster@dummy-host.example.com
    ##DocumentRoot "/xampp/htdocs/dummy-host.example.com"
    ##ServerName dummy-host.example.com
    ##ServerAlias www.dummy-host.example.com
    ##ErrorLog "logs/dummy-host.example.com-error.log"
    ##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>

##<VirtualHost *:80>
    ##ServerAdmin webmaster@dummy-host2.example.com
    ##DocumentRoot "/xampp/htdocs/dummy-host2.example.com"
    ##ServerName dummy-host2.example.com
    ##ErrorLog "logs/dummy-host2.example.com-error.log"
    ##CustomLog "logs/dummy-host2.example.com-access.log" common
##</VirtualHost>


<VirtualHost *:80>
    ServerAdmin my@example.com
    DocumentRoot "C:\web_developer\myProject"
    ServerName test.tw
    DirectoryIndex index.php
    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin my@example.com
    DocumentRoot "C:\web_developer\myProject\shop"
    ServerName shop.test.tw
    DirectoryIndex index.php
    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>

 

728x90
300x250