Laravel 6.2应用在Heroku上;路由不起作用。

huangapple go评论68阅读模式
英文:

Laravel 6.2 app on heroku; routes not working

问题

我已成功将 Laravel 6.2 应用部署到 Heroku,并且它正常运行,直到我尝试访问除主要登陆页面之外的任何其他路由。

我的日志(为了可读性而剪切):

2020-01-04T04:54:17.512849+00:00 heroku[router]: 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 [error] 145#0: *131 open() "/app/public/service" failed (2: No such file or directory), client: 10.81.170.215, server: localhost, request: "GET /service HTTP/1.1", host: "ridgearchitectsandengineers.herokuapp.com", referrer: "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:

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

我的 .htaccess 文件如下:

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

    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]
</IfModule>
英文:

I have successfully deployed a laravel 6.2 app on heroku and it working fine, until i try to access any other routes other than main landing page.

My log (Snipped for readability):

> 2020-01-04T04:54:17.512849+00:00 heroku[router]: 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 [error] 145#0: *131 open() "/app/public/service" failed (2: No such file or directory), client: 10.81.170.215, server: localhost, request: "GET /service HTTP/1.1", host: "ridgearchitectsandengineers.herokuapp.com", referrer: "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

The routes are working fine in my local machine though.
I am putting my Procfile as well if it is relevant:

> web: vendor/bin/heroku-php-nginx public/

My .htaccess :

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

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]

</IfModule>

答案1

得分: 1

以下是翻译好的内容:

"it might be late, but have you tried change the Procfile using apache2 instead of nginx? If it's running, it could be that you need to add an additional nginx configuration file and edit the Procfile so that the web engine will use your custom nginx config in case that you still want to use nginx as your web engine.

based on the example that Heroku gave, the nginx.conf file would be like this:

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;
}

and the Procfile would be like this:

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

you can see more information at this site.

英文:

it might be late, but have you tried change the Procfile using apache2 instead of nginx? If it's running, it could be that you need to add an additional nginx configuration file and edit the Procfile so that the web engine will use your custom nginx config in case that you still want to use nginx as your web engine.

based on the example that Heroku gave, the nginx.conf file would be like this:

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&#39;t accessible directly, but only through a rewrite
    internal;
}

and the Procfile would be like this:

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

you can see more information at this site.

huangapple
  • 本文由 发表于 2020年1月4日 12:47:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/59587978.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定