【问题标题】:I need "/var/www" but Apache2 try to use an empty "/var/www/html"我需要“/var/www”,但 Apache2 尝试使用空的“/var/www/html”
【发布时间】:2014-03-16 21:04:55
【问题描述】:

这几天我睡在我的http://localhost 上工作,阅读/var/www 的页面...

我在 Apache2 日志中发现“AH00094”错误,并且(Apache2 创建?)一个惊讶的/var/www/html,Apache2 尝试使用。

现在我的http://localhost/anything 不起作用(浏览器出现错误 404)。

如何解决?我需要找回我的 http://localhost 处理 /var/www 的文件!

上下文

我正在使用带有 Apache2 的 Ubuntu12,所有默认和标准。

我检查了tail /var/log/apache2/error.log 的错误日志,以找出 Apache 显示的确切路径

 ... [core:notice] [pid 1597] AH00094: Command line: '/usr/sbin/apache2'
 ... [:error] [pid 1604] [client 127.0.0.1:40624] script '/var/www/html/info.php' not found or unable to stat

文件夹/var/www/html 是新的,所有,如'/var/www/info.php',都在/var/www,而不是/var/www/html

fixed the "AH00094" error编辑

 sudo nano /etc/apache2/apache2.conf

在最后一行添加

 ServerName localhost

(现在没有关于 localhost 的日志错误,但没有任何作用)

PS:我检查了其他相关问题,但不是同一个问题:Permissions for /var/www/htmlAttempting to use symbolic link for var/www/html


我害怕使用 clues of this answer ... 在我的 Ubuntu 中没有 .conf 指示的文件。我必须创建它吗?安全吗?


正如@RahilWazir 所建议的,这也是我的“/etc/apache2/sites-available/000-default.conf”,

  <VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com
  
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
  
    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn
  
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
  
    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
  </VirtualHost>
  
  # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

【问题讨论】:

  • 粘贴/etc/apache2/sites-available/default文件的内容。
  • 感谢@RahilWazir!好吧,只有这两个文件,000-default.confdefault-ssl.conf,我可以用000-default.conf吗?
  • 是的,请显示内容。
  • Ops,我编辑了问题,现在你可以看到我的 000-default.conf
  • 在那里你可以看到它DocumentRoot /var/www/html?将其更改为DocumentRoot /var/www

标签: apache2 directory


【解决方案1】:

看这里:

Why has the apache2 www dir been moved to /var/www/html?

对于 Debian 中的 htdocs,默认目录显然(我们也很惊讶)从 /var/www 移动到 /var/www/html,Ubuntu 复制了这个更改。给出的理由有些合理,但升级路径可能是“有趣的”(就像中国谚语中所说的那样)......正如你所遇到的那样。

【讨论】:

    【解决方案2】:

    如果您想使用/www 作为根文件夹而不是/www/html,您可以简单地编辑apache2 配置文件以拥有/var/www

    编辑 000-default.conf

    sudo gedit /etc/apache2/sites-available/000-default.conf
    

    然后改变

    DocumentRoot /var/www/html 
    

    DocumentRoot /var/www
    

    重启apache2服务器:

    sudo service apache2 restart
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-12
      • 2020-04-26
      • 2012-07-28
      • 2015-03-06
      • 2020-01-10
      • 2017-02-28
      • 2020-07-04
      • 2022-01-09
      相关资源
      最近更新 更多