Apache-Httpd
不同子目錄的不同虛擬主機(Apache)?
我想為 150 個使用者託管一個網頁。每個使用者都將擁有一個唯一的 url 網頁
url/username/index.html
。這裡的使用者名對於所有使用者都是唯一的,其餘的都是通用的。那麼我需要在 Apache Server 中創建 150 個虛擬主機還是有其他出路?
您可以使用映射的mod_userdir啟用每個使用者的 Web 目錄
http://example.com/~username/index.html
到對應的文件
/home/username/public_html/index.html
預設情況下在使用者目錄中。
要擺脫波浪號,您可以使用 Apache 的重寫引擎並禁止訪問以 es 開頭的所有 URL,
~
並使用Alias
es 將各個路徑映射到其使用者目錄。將此添加到您的 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 # ...
如果您不需要提供任何文件
DocumentRoot
,則可以使用 1AliasMatch
而不是 150Alias
es:# map all paths to user dirs AliasMatch ^/([^/]+)(/.*)?$ /home/$1/public_html$2
您需要在您的伺服器上啟用
mod_userdir
並mod_rewrite
在 Debian 上執行此操作a2enmod
並重新啟動。sudo a2enmod userdir rewrite sudo service apache2 restart