on
(8) 워드프레스를 위한 리눅스 서버 구축 - 웹서버2 (가상호스트1)
(8) 워드프레스를 위한 리눅스 서버 구축 - 웹서버2 (가상호스트1)
Linux/서버구축 1.2.3... (8) 워드프레스를 위한 리눅스 서버 구축 - 웹서버2 (가상호스트1)
728x90
반응형
Apache HTTP 2.4.x Virtual Host
한 대의 서버에 두 개 이상의 웹사이트를 운영해야 한다면 가상호스트 설정이 필요하다.
구축중인 서버에 root 계정을 제외한
필요한 계정을 추가로 생성하고
각 계정별 홈디렉토리에 서브 디렉토리를 생성하여
각기다른 도메인을 각각의 디렉토리에 설정하여
별도의 웹사이트를 구축할 수 있는 환경을 만들어보자
Apache 2.4의 자세한 설정은 Apache HTTP Server Version 2.4 문서를 참고하자.
지난 글 (7) 워드프레스를 위한 리눅스 서버 구축 - 네임서버2 (도메인설정) 에서 네임서버 설정을 테스트 했었던 goodmankorea.kr 의 웹문서 저장 디렉토리는 /var/www 이다. 이는 Apache HTTP SERVER의 기본 설정값이며, /etc/httpd/conf/httpd.conf 에 설정되어 있다.
만약 또다른 도메인을 등록하여 별도의 웹사이트를 구축해야 한다면 /var/www 이외의 다른 디렉토리를 사용해야 할 것이다. 네임서버에서 설정한 여러개의 도메인을 웹서버의 원하는 디렉토리에 연결해야 한다.
/etc/httpd/conf.d/userdir.conf 를 열어보자.
# # UserDir: The name of the directory that is appended onto a user's home # directory if a ~user request is received. # # The path to the end user account 'public_html' directory must be # accessible to the webserver userid. This usually means that ~userid # must have permissions of 711, ~userid/public_html must have permissions # of 755, and documents contained therein must be world-readable. # Otherwise, the client will only receive a "403 Forbidden" message. # # # UserDir is disabled by default since it can confirm the presence # of a username on the system (depending on home directory # permissions). # UserDir disabled # # To enable requests to /~user/ to serve the user's public_html # directory, remove the "UserDir disabled" line above, and uncomment # the following line instead: # #UserDir public_html # # Control access to UserDir directories. The following is an example # for a site where these directories are restricted to read-only. # AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS
위에서 UserDir disabled 을 enabled로 수정하자. 그리고 가장 마지막줄에 다음의 4줄을 추가하자.
Require all granted AllowOverride None
아직 가상호스트의 설정이 모두 끝난 것은 아니지만 지금까지의 설정으로 특정 도메인(특정 웹사이트)의 웹문서가 저장될 디렉토리를 /home/pius 하위의 원하는 디렉토리로 설정할 수 있게 된 것이다. 지금까지 설정한 userdir.conf의 내용은 다음과 같을 것이다.
# # UserDir: The name of the directory that is appended onto a user's home # directory if a ~user request is received. # # The path to the end user account 'public_html' directory must be # accessible to the webserver userid. This usually means that ~userid # must have permissions of 711, ~userid/public_html must have permissions # of 755, and documents contained therein must be world-readable. # Otherwise, the client will only receive a "403 Forbidden" message. # # # UserDir is disabled by default since it can confirm the presence # of a username on the system (depending on home directory # permissions). # UserDir enabled # # To enable requests to /~user/ to serve the user's public_html # directory, remove the "UserDir disabled" line above, and uncomment # the following line instead: # #UserDir public_html # # Control access to UserDir directories. The following is an example # for a site where these directories are restricted to read-only. # AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS Require all granted AllowOverride None
만약 phreun 이라는 계정에도 웹사이트와 연계된 별도의 디렉토리를 생성할 계획이라면 마지막 4 줄을 추가해 줄 수 있다. 아래와 같다.
# # UserDir: The name of the directory that is appended onto a user's home # directory if a ~user request is received. # # The path to the end user account 'public_html' directory must be # accessible to the webserver userid. This usually means that ~userid # must have permissions of 711, ~userid/public_html must have permissions # of 755, and documents contained therein must be world-readable. # Otherwise, the client will only receive a "403 Forbidden" message. # # # UserDir is disabled by default since it can confirm the presence # of a username on the system (depending on home directory # permissions). # UserDir enabled # # To enable requests to /~user/ to serve the user's public_html # directory, remove the "UserDir disabled" line above, and uncomment # the following line instead: # #UserDir public_html # # Control access to UserDir directories. The following is an example # for a site where these directories are restricted to read-only. # # # AllowOverride FileInfo AuthConfig Limit Indexes # Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec # Require method GET POST OPTIONS # Require all granted AllowOverride All Require all granted AllowOverride None
위에서 두 개의 계정(pius와 phreun)의 홈디렉토리의 설정이 같기 때문에 아래와 같이 /home 디렉토리를 한 번에 설정하는 것도 가능하다.
Require all granted AllowOverride None
계정별로 구분을 정의하는 것은 AllowOverride 를 All 혹은 None로 별도로 설정할 수 있다는 장점이 있지만 이것 또한 각 도메인의 세부 설정에서 다시 정의해 줄 수 있기는 하다. 구문에서 사용할 수 있는 각종 설정들은 기초적인 것을 이지만 보안와 직결되는 중요한 설정이기에 신중해야 한다. 워드프레스와 같이 .htaccess 를 사용해야 하는 경우와 그렇지 않은 경우를 구분하여 각 계정별 혹은 조금더 세분화하여 각 디렉토리(웹사이트)별로 각기 다른 설정을 해줄 수 있다는 것이다. 예를 들어서 워드프레스로 웹사이트를 제작하려 한다면 .htaccess 를 root 계정으로 만들어서 제공하므로써 각 계정이 직접 수정이나 삭제를 못하게 할 수도 있을 것이다.
조금더 자세한 세부설정 또한 Apache HTTP Server Version 2.4 문서의 AllowOverride 와 Option 에 대한 설명를 참고하자.
728x90
반응형
from http://aegypius.tistory.com/103 by ccl(S) rewrite - 2021-04-18 16:25:05