Heroku 403禁止访问错误

14

我部署了一个PHP应用程序,当我访问URL时,出现以下错误:

Forbidden

You don't have permission to access / on this server.

我猜它试图进入app/目录,但是无法进入。


我的项目结构:

my-project
|
|-> app/
|-> public/ (index.php inside here that takes care of routing)
Procfile
composer.json
etc.

日志显示的内容:
Jul 24 12:44:08 cryptic-beyond-39147 app/web.1:  [Sun Jul 24 19:44:07.846582 2016] [autoindex:error] [pid 99:tid 139960748263168] [client 10.179.164.130:28253] AH01276: Cannot serve directory /app/: No matching DirectoryIndex (index.php,index.html,index.htm) found, and server-generated directory index forbidden by Options directive 
Jul 24 12:44:08 cryptic-beyond-39147 app/web.1:  10.179.164.130 - - [24/Jul/2016:19:44:07 +0000] "GET / HTTP/1.1" 403 209 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36 
Jul 24 12:44:13 cryptic-beyond-39147 heroku/router:  at=info method=GET path="/" host=cryptic-beyond-39147.herokuapp.com request_id=9b5e81de-440b-4001-90a4-bc94ee891d3c fwd="89.210.178.134" dyno=web.1 connect=0ms service=1ms status=403 bytes=373 

Procfile

web: vendor/bin/heroku-php-apache2 public/

.htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    AddType 'text/css; charset=UTF-8' css

</IfModule>

似乎Heroku希望Procfile中包含public目录,无论您的公共文件夹名称是什么。如果您在项目根目录中有一个index.php,则可能可以省略该文件。 - Timo
6个回答

16

恩,我找到了解决方案。

我的Procfile文件有一个“.txt”扩展名(所以是Procfile.txt),但实际上只需要叫做Procfile。

这是一个很傻的错误,但我想留下答案供以后参考。也许可以为其他人节省时间。


3
如果你仍然遇到这个问题,需要注意文件名是区分大小写的。正确的文件名应该是 Procfile 而不是 procfile。我花了两个小时才发现这个问题。不要和我一样。 - Raymond Ativie
感谢您留下的回复。 - Guilherme Felipe Reis
1
@RaymondAtivie的评论帮了我很多。由于某种原因,我以为文件名叫做Profile!! - Abdelalim Hassouna

5

我也遇到了同样的问题,因为在根目录中没有index.php文件,所以什么都没有得到,导致了这个错误。如果你也有同样的问题,在Heroku应用程序链接后面只需输入你的主页PHP文件即可。例如 - app/custom.php。


1
一个非常简单且小巧的解决方案:使用名为 ProcFile 的文件。我将其命名为 ProcFile,但问题在于需要将 ProcFile 重命名为 Procfile,只需将第一个字母大写即可。

1

我曾经遇到过同样的问题,通过创建index.php文件来解决了这个问题。


@jmoerdyk - 这实际上是针对问题症状的一个有效答案。 - Rohit Gupta
@ юра снітар - 但是你应该解释一下为什么这样可以解决问题。 - Rohit Gupta

0

非常奇怪的错误! Procfile 对我来说不是问题的原因。

由于某种原因,当我在根目录下创建一个名为“app”的空目录时,问题得到了解决。


0
我有一个类似的问题:
我的index.php中使用了include_once('index.html') 更改为header('Location: /index.html')就可以了。
注意,index.php和index.html都在根目录。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接