简体   繁体   English

在Ubuntu上为apache2启用多个webroot

[英]Enable multiple webroot for apache2 on Ubuntu

I'm using apache2 on my ubuntu 13.10 machine, I have added another config file named paul under /etc/apache2/sites-available directory to make my file under /home/paul/public_html/ accessible on internet: 我在ubuntu 13.10机器上使用apache2 ,我在/ etc / apache2 / sites-available目录下添加了另一个名为paul的配置文件,以使我的文件在/ home / paul / public_html /下可通过Internet访问:

root@localhost:/etc/apache2/sites-available# ls -ltr
-rw-r--r-- 1 root root  950 Feb  7  2012 default
-rw-r--r-- 1 root root  978 Jun 23 10:54 paul

After than changes, my files under /var/www is not accessible on URL anymore, unless I change DocumentRoot from / home/paul/public_html to /var/www , but that would disable accessibility for /home/paul/public_html/ 经过更改之后,除非再将 DocumentRoot从/ home / paul / public_html更改为/ var / www ,否则无法再通过URL访问我在/ var / www下的文件,但这会禁用/ home / paul / public_html /

/etc/apache2/sites-available/paul : / etc / apache2 / sites-available / paul:

    DocumentRoot /home/paul/public_html
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>

Is there any way of configuration to enable /var/www and /home/paul/pubilc_html as webroot at the same time? 有什么配置方法可以同时将/ var / www/ home / paul / pubilc_html启用为webroot? Is it required any setting on /etc/apache2/apache2.conf ? /etc/apache2/apache2.conf上是否需要任何设置? Any ideas would be appreciated, thanks. 任何想法将不胜感激,谢谢。

You can accomplish this easily with an alias directive . 您可以使用别名指令轻松完成此操作。 In /etc/apache2/sites-available/default just add an Alias for the URL. /etc/apache2/sites-available/default只需为URL添加一个Alias

<VirtualHost *:80>
        ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/

        Alias /paul /home/paul/public_html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Now the contents of /home/paul/public_html should be available at www.example.com/paul 现在/home/paul/public_html应该在www.example.com/paul上可用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM