[Ubuntu] 우분투 VirtualHost - 가상호스트 및 도메인 설정하기 > 기술자료 | 해피정닷컴

[Ubuntu] 우분투 VirtualHost - 가상호스트 및 도메인 설정하기 > 기술자료

본문 바로가기

사이트 내 전체검색

[Ubuntu] 우분투 VirtualHost - 가상호스트 및 도메인 설정하기 > 기술자료

Linux [Ubuntu] 우분투 VirtualHost - 가상호스트 및 도메인 설정하기

페이지 정보


본문

우분투에서는 이 가상호스트가 /etc/apache2/sites-available/default 파일이다. 
그러므로 이 파일에 지정되어 있는 ServerName과 DocumentRoot 지시자가 주호스트를 가리키게 되므로 기존에 사용하던 주호스트가 있다면 이 파일에 그 내용을 작성하면 된다. 이 파일은 또한 요청된 적절한 가상호스트를 찾지 못하게 되면 대신 보여주게될 페이지 작성의 용도로도 사용된다.


Ⅰ. apache2

1. apache2 의 설치 경로를 확인
root@happyjung:/# find / -name sites-available -print
/etc/apache2/sites-available


2. VirtualHost용 디렉토리 생성
# 아파치의 가상호스트로 사용할 디렉토리를 생성한다.
# example.com이라는 도메인 이름으로 디렉토리 생성 
root@happyjung:/# mkdir -p /var/www/example.com/public_html 

# log들이 저장될 디렉토리를 생성 
root@happyjung:/# mkdir /var/www/example.com/logs


3. 디렉토리 권한 변경
# 가상호스트의 파일들이 들어갈 public_html 의 소유권한을 사용자ID와 사용자그룹으로 변경한다. $USER에 가상호스트를 사용할 사용자ID와 사용자그룹으로 변경하면 된다.
root@happyjung:/# chown -R $USER.$USER /var/www/example.com/public_html

# 누구나 접근해서 읽을수 있게 접근권한을 변경한다.
root@happyjung:/# chmod -R 755 /var/www


4. 인덱스 파일 생성
# 사이트 확인을 위해서 index.html 파일을 생성한다.
root@happyjung:/# vi /var/www/example.com/public_html/index.html

  <html>
  <body>
    <h1>Hellow, World!</h1>
    <h2>Here is example.com</h2>
  </body>
  </html>


5. VirtualHost 파일 생성
# 우분투에서 기본값으로 제공하는 가상호스트 파일을 복사한다.
root@happyjung:/# cp /etc/apache2/sites-available/default /etc/apache2/sites-available/example.com


6. VirtualHost 설정
# 가상호스트 파일을 수정하기 위해 파일을 연다.
root@happyjung:/# vi /etc/apache2/sites-available/example.com

# ServerAdmin 에 에러발생시 이메일 연락처 등록
ServerAdmin webmaster@example.com

# ServerName 이 누락되어 있는데 이 곳에 가상호스트에서 사용할 도메인명 입력
ServerName example.com

# ServerAlias 는 별칭, www.example.com 으로 접속해도 example.com 으로 접속된다(네임서버에 관련사항이 등록되어 있어야 한다).
ServerAlias www.example.com

#DocumentRoot 는 가상호스트로 사용될 주소입력
DocumentRoot /var/www/example.com/public_html

#찾는 문서가 없을경우 보여지게 될 에러문서를 직접 정할 수도 있다.
ErrorDocument 404 /404.html

# 디렉토리 지시자중에 /var/www 에 대한 내용을 사용할 가상호스트 디렉토리 주소로 변경
# Options 값중에 Indexes 제거(이 값이 존재하면 가상호스트로 사용될 주소의 파일이 리스팅되어 보안상 위험하다).
# AllowOverride 는 워드프레스처럼 .htaccess 파일을 사용하는 경우 값을 All로 변경
<Directory /var/www/example.com/public_html>
  Options FollowSymLinks
  AllowOverride All
  Order allow,deny
  allow from all 
</Directory>

# 로그가 작성될 위치를 지정한다(이를 따로 분리하지 않으면 /var/log/apache2 디렉토리 이하에 모든 가상호스트의 로그가 기록되니 분리하도록 한다).
ErrorLog /var/www/example.com/logs/error.log
CustomLog /var/www/example.com/logs/access.log combined


7. VirtualHost 활성화
# 생성하고 수정한 파일을 등록한다.
root@happyjung:/# a2ensite example.com
root@happyjung:/# service apache2 restart




Ⅱ-1. nginx 도메인 설정하기

1. nginx 의 설치 경로를 확인
root@happyjung:/# find / -name sites-available -print
/etc/nginx/sites-available


2. 폴더 이동
root@happyjung:# cd /etc/nginx/sites-available/
default


3. default 파일에 도메인 설정 추가
root@happyjung:# vi /etc/nginx/sites-available/default


Ⅱ-2. nginx 가상호스트 설정하기

1. nginx 의 설치 경로를 확인
root@happyjung:/# find / -name sites-available -print
/etc/nginx/sites-available


2. VirtualHost용 디렉토리 생성
# nginx 의 가상호스트로 사용할 디렉토리를 생성한다.
# example.com이라는 도메인 이름으로 디렉토리 생성 
root@happyjung:/# mkdir -p /var/www/example.com/public_html 

# log들이 저장될 디렉토리를 생성 
root@happyjung:/# mkdir /var/www/example.com/logs


3. 디렉토리 권한 변경
# 가상호스트의 파일들이 들어갈 public_html 의 소유권한을 사용자ID와 사용자그룹으로 변경한다. $USER에 가상호스트를 사용할 사용자ID와 사용자그룹으로 변경하면 된다.
root@happyjung:/# chown -R $USER.$USER /var/www/example.com/public_html

# 누구나 접근해서 읽을수 있게 접근권한을 변경한다.
root@happyjung:/# chmod -R 755 /var/www


4. 인덱스 파일 생성
# 사이트 확인을 위해서 index.html 파일을 생성한다.
root@happyjung:/# vi /var/www/example.com/public_html/index.html

  <html>
  <body>
    <h1>Hellow, World!</h1>
    <h2>Here is example.com</h2>
  </body>
  </html>


5. VirtualHost 파일 생성
# 우분투에서 기본값으로 제공하는 가상호스트 파일을 복사한다.
root@happyjung:/# cp /etc/nginx/sites-available/default /etc/apache2/sites-available/example.com


6. VirtualHost 설정
# 가상호스트 파일을 수정하기 위해 파일을 연다.
root@happyjung:/# vi /etc/nginx/sites-available/example.com

# ServerAdmin 에 에러발생시 이메일 연락처 등록
ServerAdmin webmaster@example.com

# ServerName 이 누락되어 있는데 이 곳에 가상호스트에서 사용할 도메인명 입력
ServerName example.com

# ServerAlias 는 별칭, www.example.com 으로 접속해도 example.com 으로 접속된다(네임서버에 관련사항이 등록되어 있어야 한다).
ServerAlias www.example.com

#DocumentRoot 는 가상호스트로 사용될 주소입력
DocumentRoot /var/www/example.com/public_html

#찾는 문서가 없을경우 보여지게 될 에러문서를 직접 정할 수도 있다.
ErrorDocument 404 /404.html

# 디렉토리 지시자중에 /var/www 에 대한 내용을 사용할 가상호스트 디렉토리 주소로 변경
# Options 값중에 Indexes 제거(이 값이 존재하면 가상호스트로 사용될 주소의 파일이 리스팅되어 보안상 위험하다).
# AllowOverride 는 워드프레스처럼 .htaccess 파일을 사용하는 경우 값을 All로 변경
<Directory /var/www/example.com/public_html>
  Options FollowSymLinks
  AllowOverride All
  Order allow,deny
  allow from all 
</Directory>

# 로그가 작성될 위치를 지정한다(이를 따로 분리하지 않으면 /var/log/apache2 디렉토리 이하에 모든 가상호스트의 로그가 기록되니 분리하도록 한다).
ErrorLog /var/www/example.com/logs/error.log
CustomLog /var/www/example.com/logs/access.log combined


7. VirtualHost 활성화
root@happyjung:/etc/nginx/sites-available# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

root@happyjung:/etc/nginx/sites-available# systemctl restart nginx



참고자료
http://webdir.tistory.com/213
https://idchowto.com/?p=13477
http://eeje.tistory.com/entry/NGINX-가상-호스트Virtual-Host-설정-Ubuntu-1604에서

댓글목록

등록된 댓글이 없습니다.


Total 2,633건 3 페이지
  • RSS
기술자료 목록
2593
Android   3336  2023-03-07 12:06 ~ 2023-03-20 11:02  
2592
Android   3292  2023-03-07 11:28 ~ 2023-03-07 11:35  
2591
호스팅   3084  2023-03-06 15:52 ~ 2023-12-18 16:54  
2590
JavaScript   3462  2023-02-27 17:26 ~ 2023-12-06 08:33  
2589
JavaScript   3707  2023-02-22 17:33 ~ 2023-02-24 21:08  
2588
호스팅   3650  2023-02-17 17:17  
2587
그누보드   3376  2023-02-03 16:25  
2586
HTML   3291  2023-02-02 13:54 ~ 2023-02-03 06:02  
2585
Search   3519  2023-02-01 15:16 ~ 2023-02-01 16:15  
2584
MySQL   2887  2023-01-30 12:11 ~ 2023-01-30 12:23  
2583
JavaScript   4082  2023-01-27 17:42  
2582
영카트   2155  2023-01-27 11:18 ~ 2023-01-27 14:12  
2581
그누보드   2118  2023-01-20 19:39 ~ 2023-01-20 23:13  
2580
Search   2812  2023-01-18 20:05 ~ 2023-01-18 20:35  
2579
호스팅   3000  2023-01-12 10:58 ~ 2023-01-12 10:58  
2578
APP   2259  2023-01-11 18:09 ~ 2023-01-11 18:51  
2577
Android   2718  2023-01-11 09:57 ~ 2024-01-31 18:23  
2576
그누보드   2838  2023-01-06 10:36  
2575
Android   3057  2023-01-04 20:45 ~ 2023-05-23 09:05  
2574
Android   3637  2023-01-03 18:43 ~ 2023-05-01 10:57  

검색

해피정닷컴 정보

회사소개 회사연혁 협력사 오시는길 서비스 이용약관 개인정보 처리방침

회사명: 해피정닷컴   대표: 정창용   전화: 070-7600-3500   팩스: 042-670-8272
주소: 서울센터 (08393) 서울시 구로구 디지털로32가길 16 파트너스타워2차 1206-280호
        대전센터 (34368) 대전시 대덕구 대화로 160 대전산업용재유통단지 지원1동 205호
개인정보보호책임자: 정창용   사업자번호: 119-05-36414
통신판매업신고: 2014-서울구로-0074 [사업자등록확인]  
Copyright 2001~2024 해피정닷컴. All Rights Reserved.