Reputation: 1882
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/
Upvotes: 8
Views: 5255
Reputation: 428
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
Upvotes: 18
Reputation: 1882
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/
Upvotes: 1
Reputation: 800
Found a solution on http://laravel.com/docs/4.2/installation#pretty-urls
I has the same problem. Basically, I just added .htaccess file on the /public folder and everything works now.
Upvotes: 0