首页 > 解决方案 > Heroku 上的 Laravel 6.2 应用程序;路线不工作

问题描述

我已经在 heroku 上成功部署了一个 laravel 6.2 应用程序并且它工作正常,直到我尝试访问除主登录页面之外的任何其他路线。

我的日志(为便于阅读而截取):

2020-01-04T04:54:17.512849+00:00 heroku[路由器]: at=info method=GET path="/service" host=ridgearchitectsandengineers.herokuapp.com request_id=261880df-693e-4dda-85e5-5a20720a21fd fwd= “110.44.124.147” dyno=web.1 connect=0ms service=1ms status=404 bytes=691 protocol=https 2020-01-04T04:54:17.513095+00:00 app[web.1]: 2020/01/04 04:54:17 [错误] 145#0: *131 open() "/app/public/service" 失败(2:没有这样的文件或目录),客户端:10.81.170.215,服务器:localhost,请求:“GET /service HTTP/1.1”,主机:“ridgearchitectsandengineers.herokuapp.com”,引用者:“ https://ridgearchitectsandengineers.herokuapp.com/ ” 2020-01-04T04:54:17.516131+00:00 app[web.1] : 10.81.170.215 - - [04/Jan/2020:04:54:17 +0000] "GET /service HTTP/1.1" 404 548 "https://ridgearchitectsandengineers.herokuapp.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36

不过,这些路线在我的本地机器上运行良好。如果相关,我也会将我的 Procfile 放入:

网站:供应商/bin/heroku-php-nginx public/

我的 .htaccess :

选项 -MultiViews -Indexes

RewriteEngine On

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

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

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

标签: laravelherokularavel-6.2

解决方案


可能已经晚了,但是您是否尝试过使用 apache2 而不是 nginx 更改 Procfile?如果它正在运行,则可能是您需要添加一个额外的 nginx 配置文件并编辑 Procfile,以便 Web 引擎将使用您的自定义 nginx 配置,以防您仍想使用 nginx 作为您的 Web 引擎。

根据 Heroku 给出的示例, nginx.conf 文件将如下所示:

location / {
    # try to serve file directly, fallback to rewrite
    try_files $uri @rewriteapp;
}

location @rewriteapp {
    # rewrite all to index.php
    rewrite ^(.*)$ /index.php/$1 last;
}

location ~ ^/index\.php(/|$) {
    try_files @heroku-fcgi @heroku-fcgi;
    # ensure that /index.php isn't accessible directly, but only through a rewrite
    internal;
}

Procfile 是这样的:

web: vendor/bin/heroku-php-nginx -C nginx.conf public/

您可以在此站点上查看更多信息。


推荐阅读