Kako omogućiti Apache Userdir modul na RHEL/CentOS


Korisnički imenik ili Userdir je Apache modul, koji omogućava preuzimanje korisničkih imenika preko Apache web servera koristeći http://example.com/ ~user/ sintaksa.

Na primjer, kada je modul mod_userdir omogućen, korisnički računi na sistemu će moći pristupiti sadržaju u svojim kućnim direktorijima sa svijetom preko Apache web servera.

U ovom članku ćemo vam pokazati kako omogućiti Apache userdirs (mod_userdir) na RHEL, CentOS i Fedora serveri koji koriste Apache web server.

Ovaj vodič pretpostavlja da već imate instaliran Apache web server na vašoj Linux distribuciji. Ako niste, možete ga instalirati na sljedeći način...

Korak 1: Instalirajte Apache HTTP server

Da biste instalirali Apache web server, koristite sljedeću naredbu na vašoj Linux distribuciji.

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

Korak 2: Omogućite Apache Userdirs

Sada morate da konfigurišete svoj Apache web server da koristi ovaj modul u konfiguracionoj datoteci /etc/httpd/conf.d/userdir.conf, koja je već konfigurisana sa najboljim opcijama.

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

Zatim potvrdite sadržaj nešto kao ispod.

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>

Da biste dozvolili nekolicini korisnika da pristupe direktorijima UserDir, ali ne bilo kome drugom, koristite sljedeću postavku u konfiguracijskoj datoteci.

UserDir disabled
UserDir enabled testuser1 testuser2 testuser3

Da biste dozvolili svim korisnicima da imaju pristup direktorijima UserDir, ali to onemogućite za nekoliko korisnika, koristite sljedeću postavku u konfiguracijskoj datoteci.

UserDir enabled
UserDir disabled testuser4 testuser5 testuser6

Nakon što napravite postavke konfiguracije prema vašim zahtjevima, morate ponovo pokrenuti Apache web server da biste primijenili nedavne promjene.

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

Korak 3: Kreiranje korisničkih direktorija

Sada trebate kreirati public_html direktorij/direktorije u korisničkim/korisničkim kućnim direktorijima. Na primjer, ovdje kreiram public_html direktorij u tecmintovom korisničkom kućnom direktoriju.

mkdir /home/tecmint/public_html

Zatim primijenite ispravne dozvole na direktorije home i public_html.

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

Također, postavite ispravan SELinux kontekst za Apache homedirs (httpd_enable_homedirs).

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

Korak 4: Testirajte omogućen Apache Userdir

Konačno, provjerite Userdir usmjeravanjem vašeg pretraživača na ime servera ili IP adresu nakon čega slijedi korisničko ime.

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

Ako želite, također možete testirati HTML stranice i PHP informacije kreiranjem sljedećih datoteka.

Kreirajte datoteku /home/tecmint/public_html/test.html sa sljedećim sadržajem.

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

Kreirajte datoteku /home/tecmint/public_html/test.php sa sljedećim sadržajem.

<?php
  phpinfo();
?>

To je sve! U ovom članku smo objasnili kako omogućiti modul Userdir da omogući korisnicima da dijele sadržaj iz svojih kućnih direktorija. Ako imate pitanja u vezi sa ovim člankom, slobodno pitajte u odeljku za komentare ispod.