Daniel Groppo
Daniel Groppo

Reputation: 59

Laravel 4.2 on Nginx getting 404 (VPS)

I'm trying to use the Laravel 4.2 on nginx. I have a VPS (Dreamhost) and I put the Laravel framework inside the root path of user (/home/vi360/) and the public path is on /home/vi360/vide360.com.br

I've been researching several ways to set up nginx for Laravel, but I'm not getting any success. Only the home page is opening (www.vide360.com.br), but all the other pages (directed by /home/vi360/app/routes.php) are returning with error 404.

I have created the /home/vi360/nginx/vide360.com.br/vide360.conf as follows:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /home/vi360/vide360.com.br;
    index index.php index.html index.htm;

    server_name [server ip address];

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

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

What am I maybe doing wrong?

Upvotes: 0

Views: 126

Answers (1)

Arun Code
Arun Code

Reputation: 1638

I guess you changed the public folder name.

Laravel looks up its files in public folder. Say your laravel application running on /home/vi360 then your public folder path will be /home/vi360/public.

Then on your nginx, it should be like

root /home/vi360/public;

Try renaming the vide360.com.br folder back to public and it will be fine. This is because the framework follows the request by booting up and forwarding it to public/index.php file.

Don't forget to restart nginx and php-fpm after the settings change.

EDIT

If the developer wants to change the public directory of laravel from public folder to other folder, say vide360.com.br, then edit your Application Service Provider (ASP) which is located at App\Providers\AppServiceProvider.php. And under the register method add the code with your new public folder name.

 $this->app->bind('path.public', function() {
        return base_path().'/vide360.com.br';
    });

Upvotes: 1

Related Questions