웹사이트 검색

RHEL/CentOS에서 Apache Userdir 모듈을 활성화하는 방법


사용자 디렉토리 또는 Userdir는 Apache 모듈로, http://example.com/을 사용하여 Apache 웹 서버를 통해 사용자별 디렉토리를 검색할 수 있습니다. ~user/ 구문.

예를 들어, mod_userdir 모듈이 활성화되면 시스템의 사용자 계정은 Apache 웹 서버를 통해 전 세계에서 자신의 홈 디렉터리에 있는 콘텐츠에 액세스할 수 있습니다.

이 문서에서는 RHEL, CentOS에서 Apache userdirs(mod_userdir)를 활성화하는 방법을 보여줍니다. Apache 웹 서버를 사용하는 Fedora 서버.

이 튜토리얼에서는 Linux 배포판에 Apache 웹 서버가 이미 설치되어 있다고 가정합니다. 아직 설치하지 않은 경우 다음 절차에 따라 설치할 수 있습니다.

1단계: Apache HTTP 서버 설치

Apache 웹 서버를 설치하려면 Linux 배포판에서 다음 명령을 사용하십시오.

yum install httpd           [On CentOS/RHEL]
dnf install httpd           [On Fedora]

2단계: Apache Userdir 활성화

이제 이미 최상의 옵션으로 구성되어 있는 /etc/httpd/conf.d/userdir.conf 구성 파일에서 이 모듈을 사용하도록 Apache 웹 서버를 구성해야 합니다.

vi /etc/httpd/conf.d/userdir.conf

그런 다음 아래와 같이 내용을 검증합니다.

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.
#
<IfModule mod_userdir.c>
    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
    UserDir enabled tecmint

    #
    # 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
</IfModule>

#
Control access to UserDir directories.  The following is an example
for a site where these directories are restricted to read-only.
#
<Directory "/home/*/public_html">
    ## Apache 2.4 users use following ##
    AllowOverride FileInfo AuthConfig Limit Indexes
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS

## Apache 2.2 users use following ##
        Options Indexes Includes FollowSymLinks        
        AllowOverride All
        Allow from all
        Order deny,allow
</Directory>

일부 사용자만 UserDir 디렉터리에 액세스할 수 있도록 허용하고 다른 사용자는 액세스할 수 없게 하려면 구성 파일에서 다음 설정을 사용하십시오.

UserDir disabled
UserDir enabled testuser1 testuser2 testuser3

모든 사용자가 UserDir 디렉토리에 액세스할 수 있도록 허용하고 일부 사용자에게 이를 비활성화하려면 구성 파일에서 다음 설정을 사용하십시오.

UserDir enabled
UserDir disabled testuser4 testuser5 testuser6

요구 사항에 따라 구성 설정을 지정한 후에는 Apache 웹 서버를 다시 시작하여 최근 변경 사항을 적용해야 합니다.

systemctl restart httpd.service  [On SystemD]
service httpd restart            [On SysVInit]

3단계: 사용자 디렉터리 생성

이제 사용자/사용자 홈 디렉터리에 public_html 디렉터리/디렉터리를 만들어야 합니다. 예를 들어, 여기서는 tecmint의 사용자 홈 디렉토리 아래에 public_html 디렉토리를 생성합니다.

mkdir /home/tecmint/public_html

그런 다음 사용자 homepublic_html 디렉터리에 올바른 권한을 적용합니다.

chmod 711 /home/tecmint
chown tecmint:tecmint /home/tecmint/public_html
chmod 755 /home/tecmint/public_html

또한 Apache homedirs(httpd_enable_homedirs)에 대한 올바른 SELinux 컨텍스트를 설정하세요.

setsebool -P httpd_enable_homedirs true
chcon -R -t httpd_sys_content_t /home/tecmint/public_html

4단계: 활성화된 Apache Userdir 테스트

마지막으로 브라우저에서 서버 호스트 이름 또는 IP 주소와 사용자 이름을 차례로 지정하여 Userdir을 확인하세요.

http://example.com/~tecmint
OR
http://192.168.0.105/~tecmint

원하는 경우 다음 파일을 생성하여 HTML 페이지와 PHP 정보를 테스트할 수도 있습니다.

다음 내용으로 /home/tecmint/public_html/test.html 파일을 생성합니다.

<html>
  <head>
    <title>TecMint is Best Site for Linux</title>
  </head>
  <body>
    <h1>TecMint is Best Site for Linux</h1>
  </body>
</html>

다음 내용으로 /home/tecmint/public_html/test.php 파일을 생성합니다.

<?php
  phpinfo();
?>

그게 다야! 이 문서에서는 사용자가 홈 디렉터리의 콘텐츠를 공유할 수 있도록 Userdir 모듈을 활성화하는 방법을 설명했습니다. 이 기사와 관련하여 궁금한 점이 있으면 아래 댓글 섹션에서 언제든지 문의하세요.