duanjing9739 2014-05-09 16:09
浏览 196
已采纳

为什么我不能让Apache2从/ var / www以外的目录中提供站点服务? [关闭]

I have a Ubuntu 12.04 server running in a VirtualBox environment. I setup a shared folder with my Windows system and this worked fine until I updated PHP to 5.5.12 from 5.3.x. I used a new source for php as it didn't seem that apt-get was letting me upgrade past 5.3.x. In the process it upgraded apache2 also. One difference that I had overlooked initially was that vhost configuration files were no longer default or mysite. The default is now 000-default.conf. And apache2.conf is only setup to load sites with configuration files that end in .conf.

The problem is not that I am getting any forbidden errors but instead apache ignores any directives telling it to use a document root elsewhere than the /var/www location. My shared directory with VirtualBox is /media/sf_sandbox/ - that's the Ubuntu directory. I disabled the default site 000-default.conf and enabled two others. Now, sandbox.dev uses files in the var/www directory and not the shared directory. It ignores the directives in the sandbox.conf file.

I read somewhere that apache by default will only serve files from the /var/www directory and that I might have to white list other directories. It didn't say how to do that. The apache2.conf file does have directives to load *.conf files from the sites-available directory. Unfortunately, it just ignores the directives telling it where the document root is on my sites. This happened after upgrading PHP from 5.3.x to 5.5.12, which also upgraded apache2.

How can I white-list other directories and tell apache to serve files from the location specified?

  • 写回答

1条回答 默认 最新

  • duanmian1085 2014-05-09 16:12
    关注

    First, this really belongs on Server Fault. That said, you ask this:

    How can I white-list other directories and tell apache to serve files from the location specified?

    There is no such thing as a “white list” for Apache. It can serve content from anywhere on your system. Even if you have a set DocumentRoot you can always use an Alias. Apache is flexible.

    So what you seem to be facing is a configuration issue. Nothing more. Nothing less. Just find the config files & adjust as needed & all should be good.

    Meaning, what do you see when you run this command listing sites-available:

    ls -la /etc/apache2/sites-available
    

    Versus this command with sites-enabled:

    ls -la /etc/apache2/sites-enabled
    

    The contents of sites-available are the real configuration files. The items in sites-enabled are just symbolic links to the files in sites-available. So when you say this:

    The default is now 000-default.conf.

    You might be mixed up. Since 000-default.conf in sites-enabled is just a symbolic link to default in sites-available that Apache actually reads configurations from. For example, the contents of sites-available on an Ubuntu 12.04 server I am on are:

    ls -la /etc/apache2/sites-available
    
    -rw-r--r-- 1 root root  913 Apr 15 16:15 default
    -rw-r--r-- 1 root root 7469 Feb 14  2012 default-ssl
    

    Then in sites-enabled it is:

    ls -la /etc/apache2/sites-enabled
    
    lrwxrwxrwx 1 root root   26 Jan 11  2013 000-default -> ../sites-available/default
    

    Note how 000-default is just a symbolic link to ../sites-available/default which is basically /etc/apache2/sites-available/default.

    Past that you need to provide more details or look into where your configs are. And you might even try running this command to see what virtual hosts your active Apache server is currently managing:

    sudo apachectl -S

    EDIT: Seems like the original poster does not have 000-default in sites-enabled. So that can be fixed with a new symbolic link like this:

    sudo ln -s /etc/apache2/sites-available/default /etc/apache2/sites-enabled/000-default
    

    Then restart Apache with a sudo service apache2 restart and try again. Hopefully this was the issue. And note that the reason default gets renamed 000-default when it’s in sites-enabled as a symbolic link is to make sure that is the very first config that is loaded.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统