【问题标题】:Apache not recognizing directories other than rootApache 无法识别除 root 以外的目录
【发布时间】:2015-03-15 15:02:58
【问题描述】:

尝试加载除 www.example.com 以外的任何内容(例如 www.example.com/something)时,我从 apache 收到一条错误消息,指出“在此服务器上未找到请求的 URL /something”。

关于问题可能是什么的任何想法? 我正在 Digital Ocean - LAMP/Ubuntu 上运行一个 laravel 应用程序。

我的 apache2.conf 文件(去除 cmets):

Mutex file:${APACHE_LOCK_DIR} default

PidFile ${APACHE_PID_FILE}

Timeout 300


KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 5


User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf


<Directory />
    Options FollowSymLinks
    AllowOverride All
    Require all denied
    RewriteEngine On
    RewriteBase /var/www/html/scheduleify/app/public
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

#<Directory /srv/>
#   Options Indexes FollowSymLinks
#   AllowOverride None
#   Require all granted
#</Directory>


AccessFileName .htaccess

<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>


LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent



IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf


Include /etc/phpmyadmin/apache.conf

编辑:也是启用站点的 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/scheduleify/public

    # 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

【问题讨论】:

  • 启用站点的外观是什么样的。
  • 添加了上面的 conf 文件内容 - 希望这能有所帮助
  • 所以 DocumentRoot 是 /var/www/html/scheduleify/public ... 你在那个目录中有 something.html 吗?
  • 这是我的下一个问题,你在 www.example.com 上得到了什么
  • 我有我的 laravel 应用程序 index.php 文件,以及应用程序的资产。

标签: apache ubuntu laravel


【解决方案1】:

Apache 是一个网络服务器——它的主要工作是向网络提供文件。如果它告诉你没有文件在

http://example.com/foo/baz/bar

那么那里没有文件。它正在正常工作

Laravel 是一个 PHP 应用程序,它通过运行文件 index.php 来工作。如果

http://example.com/
http://example.com/index.php

通过 Laravel 正确渲染,这意味着 Laravel 正在工作。

为了使网址像

http://example.com/foo/baz/bar

通过 Laravel 渲染,Laravel 在 public 文件夹中包含一个 .htaccess 文件,该文件将大多数(如果不是全部) URL 重定向到 index.php。就是这个.htaccess文件负责转

http://example.com/foo/baz/bar

进入

http://example.com/index.php/foo/baz/bar

在工作系统中,这发生在幕后。即从用户查看浏览器的角度来看,URL 仍然是http://example.com/foo/baz/bar

如果第二种形式的 URL 在您的服务器上呈现,那么几乎可以肯定是 .htaccess 问题。无论您在哪个 &lt;Directory 节点中配置您的 webroot,您都需要这样的东西

AllowOverride All

这告诉 Apache “嘿,让用户使用 .htaccess 文件重新配置您可以从 .htaccess 文件配置的所有内容。您可以找到更多信息 about AllowOverride on the apache docs site

【讨论】:

  • 我偶然发现了这一点 - 但你是对的。 AllowOverride 设置不正确。感谢您的详尽解释!
猜你喜欢
  • 2021-09-16
  • 2015-11-09
  • 2021-05-13
  • 2014-07-10
  • 2021-08-26
  • 1970-01-01
  • 2021-08-28
  • 2021-05-06
  • 2019-05-23
相关资源
最近更新 更多