Apache Web 服务器支持 UserDir 特性(即用户目录).
这个特性会将下面格式的URL:
http://www.foo.com/~bob/one/two.html
映射到目录/home/bob/www/one/two.html.
这种映射目录路径的构成还有几种其他形式,关于UserDir的内容,可以见下面的web:
1.http://www.centos.org/docs/5/html/5.1/Deployment_Guide/s3-httpd-mig-main-map.html
2.http://httpd.apache.org/docs/2.0/mod/mod_userdir.html#userdir
3.http://httpd.apache.org/docs/2.0/howto/public_html.html
实验这个特性,是在Ubuntu 10.10上进行的,Apache Web服务为apache 2.2.
设置的核心内容在上面的几个web中已经得到了说明,主要的问题是在Ubuntu中,
apache的设置方式.
apache的配置文件位于/etc/apache2中.在此,要关注的是文件apache2.conf,目录
mods-available,mods-enabled.
apache2.conf是主要配置文件,其中对module的配置使用了下面的指令:
<span style="font-size:14px;"># Include module configuration:
Include mods-enabled/*.load
Include mods-enabled/*.conf </span>
因此,和UseDir有关的module以及配置需要在目录mods-enabled进行.而目录
mods-enabled下的文件全部为对目录mods-available下文件的连接.
查看目录mods-available下和UserDir有关的文件userdir.conf,userdir.load,没有需要进行特殊修改的地方,直接使用命令更改apache的配置:
<span style="font-size:14px;">sudo a2enmod userdir</span>
然后重启Apache服务器:
sudo service apache2 restart
假设当前的用户名为bob,在其主目录下建立如下的目录与文件:
public_html/testProject/index.html
通过浏览器访问如下URL:
http://localhost/~bob/testProject/index.html
则可以正确访问.
以上的操作,是在阅读下面的web后进行的实际操作:
如果使用PHP进行开发,则还需要对apache的php module进行配置.因为在目录mods-enabled中,已经有了和php module有关的连接,直接修改文件mods-available/php5.conf.
文件修改前:
<span style="font-size:14px;"><IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_value engine Off
</Directory>
</IfModule>
</IfModule>
</span>
文件修改后:<span style="font-size:14px;"><IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
# <IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_value engine Off
# </Directory>
# </IfModule>
</IfModule>
</span>
重启Apache服务器后,即可在之前建立的测试目录下编写一个php脚本进行测试了.