Mohamed Ataala
Mohamed Ataala

Reputation: 33

Laravel routes getting not found on nginx/1.8

I use laravel 5.1 and nginx/1.8 it's the first time for me with Nginx Server

When i try to access laravel app home page the route working well

get('/', function () {
   return view('welcome');
});

But when i try to access any other page

get('/home', function () {
    return 'Home Page';
   // Or Blade Page 
  //return view('home');
});

Nginx return

The page you are looking for is not found

My settings file on /etc/nginx/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
  worker_connections 1024;
}

http {
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;

sendfile            on;
tcp_nopush          on;
tcp_nodelay         on;
keepalive_timeout   65;
types_hash_max_size 2048;

include             /etc/nginx/mime.types;
default_type        application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  localhost;
    #root        /usr/share/nginx/html;
    root         /var/www/nginx/html;
    index        index.php index.html index.htm;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

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

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
  }
}

Update the last result of /var/log/nginx/error.log

#3 /var/www/nginx/html/laravel/vendor/laravel/framework/src/Illuminate /Foundation/Exceptions/Handler.php(49): Monolog\Logger->error(Object(Symfo 2016/01/11 22:59:38 [error] 22510#0: *31 directory index of "/var/www/nginx/html/laravel/" is forbidden, client: 127.0.0.1, server: _, request: "GET /laravel/ HTTP/1.1", host: "localhost"

Note:html/laravel -> laravel is the app name

Any Suggestions ?

Upvotes: 0

Views: 1244

Answers (1)

aynber
aynber

Reputation: 23011

Root needs to point to the public folder of your laravel installation. If you've installed laravel into /var/www/nginx/html, then it should be:

 root         /var/www/nginx/html/public  

Upvotes: 1

Related Questions