0

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 ?

lagbox
  • 48,571
  • 8
  • 72
  • 83
Mohamed Ataala
  • 33
  • 1
  • 12

1 Answers1

1

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  
aynber
  • 22,380
  • 8
  • 50
  • 63
  • **html** this is the **dir** that contains my **apps** i think you means `root /var/www/nginx/html/laravel/public` Anyway i tried both but i still return `404 error` – Mohamed Ataala Jan 11 '16 at 18:44
  • Check to see where your public folder is, and set it. If you're using laravel in a subdirectory instead of its own domain, then it needs to be set in your htaccess file instead. – aynber Jan 11 '16 at 18:51
  • thanks for caring look my app name is `laravel` it's inside `html` dir now my `root /var/www/nginx/html` if you see should to set `htaccess file` in this case please help me – Mohamed Ataala Jan 11 '16 at 18:58
  • Are you trying to access the site via `domain.com` or `domain.com/laravel`? This makes a difference in if you should use nginx.conf or .htaccess. – aynber Jan 11 '16 at 19:00
  • i'm on localhost server i access site via `localhost/laravel/public` see the error pic ,if i want to access `localhost/laravel/public/home` i get an error – Mohamed Ataala Jan 11 '16 at 19:03
  • It should be `localhost/laravel/home` – aynber Jan 11 '16 at 19:38
  • `localhost/laravel/home` return `The page you are looking for is not found.` – Mohamed Ataala Jan 11 '16 at 19:44
  • I'd suggest looking at this post for using laravel in a subfolder: http://stackoverflow.com/questions/16683046/how-to-install-laravel-4-to-a-web-host-subfolder-without-publicly-exposing-app – aynber Jan 11 '16 at 20:27
  • Dear@aynbar: firstly i want to say thanks for your help , but there one note it's the same app run well with `apache` `localhost/laravelApp/public/home` But `localhost/laravelApp/public/home` return `page not found ` with `Nginx` **why this happen with Nginx but not with Apache** – Mohamed Ataala Jan 11 '16 at 20:55
  • Beyond this, I can't help. It's a configuration issue somewhere, but I can't see where the issue might be. – aynber Jan 11 '16 at 21:18