[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 40건 1 페이지
  • RSS
기술자료 목록
40
전자결제   1847  2024-09-05 09:30  
39
ClassicASP   3033  2023-09-14 08:38  
38
호스팅   4701  2023-02-17 17:17  
37
Search   3604  2023-01-18 20:05 ~ 2023-01-18 20:35  
36
Search   4841  2022-09-03 15:15  
35
도메인   4265  2022-05-24 17:48 ~ 2022-05-24 19:00  
34
도메인   17790  2020-05-26 18:12 ~ 2020-05-31 19:16  
33
Linux   7932  2019-01-21 15:38 ~ 2021-02-26 16:51  
열람
Linux   16219  2019-01-21 07:18 ~ 2020-03-31 00:18  
31
XpressEngine   12074  2018-06-08 00:32 ~ 2018-06-12 16:36  
30
도메인   10020  2018-05-10 11:28 ~ 2018-05-10 14:05  
29
도메인   11605  2017-12-19 18:41 ~ 2017-12-19 18:44  
28
그누보드   20210  2017-08-31 14:34 ~ 2025-01-07 09:44  
27
ClassicASP   12459  2017-08-30 07:34 ~ 2021-02-26 16:47  
26
WindowsServer   11710  2017-05-17 18:54  
25
그누보드   16492  2017-04-13 13:43 ~ 2017-12-06 07:23  
24
WordPress   9897  2017-02-01 21:01 ~ 2018-12-19 20:27  
23
그누보드   14490  2017-01-17 02:10  
22
도메인   12621  2016-12-13 11:17 ~ 2020-02-12 11:07  
21
WordPress   9581  2016-09-30 00:28 ~ 2020-08-28 12:11  

검색

해피정닷컴 정보

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

회사명: 해피정닷컴   대표: 정창용   전화: 070-7600-3500   팩스: 042-670-8272
주소: (34368) 대전시 대덕구 대화로 160 대전산업용재유통단지 1동 222호
개인정보보호책임자: 정창용   사업자번호: 119-05-36414
통신판매업신고: 제2024-대전대덕-0405호 [사업자등록확인]  
Copyright 2001~2025 해피정닷컴. All Rights Reserved.