Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel 5 heroku 404 not found ngix

I'm getting a pretty weird error while trying to deploy a Laravel 5 application to Heroku. If I try to access my root domain https://my-app.herokuapp.com it works fine. However, if I try to access and other domain that is / something aka https://my-app.herokuapp.com/api/v1/users it gives me a 404 not found. Heroku is actually trying to go to the folder /api/v1/users instead of reading the routes file.

here is my Procfile:

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

now if I try the same thing but with an apache server it works fine:

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

like image 213
ThreeAccents Avatar asked Jun 04 '15 06:06

ThreeAccents


2 Answers

https://devcenter.heroku.com/articles/custom-php-settings

Using a custom application level Nginx configuration

Inside the default server level configuration file Heroku uses during the startup of Nginx, it includes a very simple default application level config file. You can replace this file with your custom configuration. For example, to configure Nginx to use some rewrite rules for your Symfony2 application, you’d create a nginx_app.conf inside your application’s root directory with the following contents:

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

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

location ~ ^/(app|app_dev|config)\.php(/|$) {
    try_files @heroku-fcgi @heroku-fcgi;
    internal;
}

for laravel.

create in root directory nginx_app.conf:

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

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

location ~ ^/(app|app_dev|config)\.php(/|$) {
    try_files @heroku-fcgi @heroku-fcgi;
    internal;
}

in Procfile:

web: vendor/bin/heroku-php-nginx -C nginx_app.conf /public
like image 192
Luis Vasquez Avatar answered Nov 06 '22 04:11

Luis Vasquez


If you want to use nginx with heroku an laravel you need to add a nginx_app.conf to you public folder and then add this:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

And this is how your Procfile should look:

web: vendor/bin/heroku-php-nginx public/
like image 34
ThreeAccents Avatar answered Nov 06 '22 05:11

ThreeAccents