当前位置: 首页>>技术问答>>正文


从2.4.7版本的apache2开始,我的本地网站放在哪里?

, ,

问题描述

我最近安装了Ubuntu 14.04,然后我安装了lamp-server并将我的网页放在/var/www目录中,但是当我在浏览器中打开localhost时什么都没有。我认为这是因为Zend更新了Apache。

无论原因是什么,我想知道在哪里保存我的php文件,以便我可以从浏览器访问它们。

最佳解决思路

在Ubuntu 14.04版本发布时发布的apache2版本是2.4.7,从这个版本开始,出于安全考虑,服务器的新根目录似乎是:

/var/www/html

因此,从现在开始,您必须在此处放置(本地)网站的文件。您将来不应该再次遇到此问题。


无论如何,如果你想用另一个目录更改这个目录,你必须从/etc/apache2/sites-available/000-default.conf文件(sudo nano /etc/apache2/sites-available/000-default.conf)修改(作为root)以下行:

DocumentRoot /var/www/html

DocumentRoot /path/to/another/directory

在此之后,要使新更改生效,您必须使用以下命令重新启动Apache服务器:

sudo service apache2 restart

次佳解决思路

我没有将/etc/apache2/sites-available/000-default.conf修改为旧版本,而是保留默认的默认包文件。

原因是它在下一次升级期间不会中断,这可能会重置000-default.conf文件。此外,这些修改并不仅仅是为了惹恼我们,修改是有充分理由的,就像这个bug report in Debian explains一样。

Our webservers [sic] set the default document root to /var/www, whereas site-local administrators tend to use /var/www/example.com. This has security implications if visitors access the default document root, bypassing the /supposed/ document root of example.com. That’s problematic if sensitive data is placeѕ outside the supposed document root (e.g. consider a hypothetical /var/www/example-com-db.conf configuration file).

更好的解决方案是将站点文件从/var/www移动到/var/www/html/

# 1. move all files excluding the `html` directory
sudo mv /var/www/[!html]* /var/www/html
# 2. Move the hidden files as well which are skipped in previous command
sudo mv /var/www/.[!.]?* /var/www/html/

另外,另一种可能的解决方案是使用命令sudo a2dissite 000-default创建另一个虚拟主机并禁用默认主机

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/1580.html,未经允许,请勿转载。