サブディレクトリごとに仮想ホスト(Apache)が異なります。

サブディレクトリごとに仮想ホスト(Apache)が異なります。

150人のユーザーのためのWebページをホストしたいです。各ユーザーにはURLを介して独自のWebページがありますurl/username/index.html。ここユーザー名すべてのユーザーに一意であり、他のすべては普遍的です。

それでは、Apache Serverに150の仮想ホストを作成する必要がありますか、それとも別の方法がありますか?

ベストアンサー1

ユーザー固有のWebディレクトリを有効にできます。mod_userディレクトリどの地図

http://example.com/~username/index.html

そのファイルに

/home/username/public_html/index.html

デフォルトはユーザーディレクトリです。

チルダを削除するには、Apacheの書き換えエンジンを使用し、esで始まるすべてのURLへのアクセスを無効にし、esを~使用してAlias個々のパスをユーザーディレクトリにマップできます。

VirtualHost 構成に以下を追加します。

RewriteEngine On
# forbid URLs starting with /~
RewriteRule ^/~  -  [F]

# map individual paths to user dirs
Alias /bart    /home/bart/public_html
Alias /homer   /home/homer/public_html
Alias /lisa    /home/lisa/public_html
Alias /maggie  /home/maggie/public_html
# ...

esでファイルを提供する必要がない場合は、150 esの代わりにDocumentRoot1を使用できます。AliasMatchAlias

# map all paths to user dirs
AliasMatch ^/([^/]+)(/.*)?$  /home/$1/public_html$2

有効にする必要があり、サーバー上でmod_userdirDebianから再起動してこれを行うことができます。mod_rewritea2enmod

sudo a2enmod userdir rewrite
sudo service apache2 restart

おすすめ記事