meulruben
By:
meulruben

LEMP on Ubuntu : 404's everywhere

September 13, 2015 4.4k views
Nginx LEMP PHP Frameworks Ubuntu

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04

After following this tutorial I got a working server, I can display the info test page.
However if I test my Silex project I encounter 404's on all my routes (except the "/" route).

class HomeController implements ControllerProviderInterface {

    public function connect(Application $app) {
        $controllers = $app['controllers_factory'];

        $controllers
            ->get('/home/', array($this, 'overview'))
            ->method('GET|POST')
            ->bind('home.overview');

        $controllers->get('/', function(Application $app) {
            //return 'Test'; //Works
            return $app->redirect($app['url_generator']->generate('home.overview')); //Works
        });

        return $controllers;
    }

    public function overview(Application $app) {
        //return $app->redirect($app['url_generator']->generate('auth.register')); //Doesn't work
        return 'test'; //Doesn't work
    }
}

For the code above, the base url ("/") can show a "test" string or redirect to "/home" which is linked to the overview function.
However everything I try in that overview function doesn't work, I cannot return "test" or redirect to another url, both things that where working in the "/" route.

All of this code works local.

Error log doesn't help very much.

The 404's are they because of some bad configuration? Where to look/what to change?

1 Answer

Add the following line to your server block, replacing try_files if it already exits:

try_files $uri $uri/ /index.php?$args;
Have another answer? Share your knowledge.