最後更新: 2024-07-02
介紹
設定
啟用 Module
* 此 Module Default: Disable
a2enmod userdir
Apache settings
假設 User 都係在 /home/ftproot/ 內
<Directory /home/ftproot/*/public_html> AllowOverride None Require method GET <FilesMatch "\.(php|js|css)$"> Require all denied </FilesMatch> </Directory>
UserDir
<IfModule mod_userdir.c> UserDir disabled UserDir enabled user1 user2 UserDir public_html </IfModule>
If neither the enabled nor the disabled keywords appear in the Userdir directive,
the argument is treated as a filename pattern, and is used to turn the name into a directory specification.
說明
-
"UserDir disabled"
turns off all username-to-directory translations except those explicitly named with the enabled keyword
-
"UserDir disabled root" # space-delimited list
Usernames that appear in such a list will never have directory translation performed,
even if they appear in an enabled clause.
* "UserDir disabled root" 是沒有 "UserDir disabled" 的效果 !!
-
"UserDir enabled user1 user2"
These usernames will have directory translation performed even if a global disable is in effect.
Example 設定
# To enable requests to /~user1/ to serve the user's "public_html" directory
UserDir disabled UserDir enabled user1 UserDir public_html
Link
http://example.com/~user1/ "map to" ~user1/public_html
Limit User use it
# To allow a few users to have UserDir directories, but not anyone else, use the following:
UserDir disabled UserDir enabled user1 user2 user3
# To allow most users to have UserDir directories, but deny this to a few, use the following:
UserDir disabled user4 user5 user6
Restricted to read-only
<Directory /home/*/public_html> AllowOverride FileInfo AuthConfig Limit Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> # Restrict access controls to all HTTP methods except the named ones # <LimitExcept> and </LimitExcept> are used to enclose a group of access control directives # which will then apply to any HTTP access method not listed in the arguments <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory>