2

I just set up nginx web server inside my ubunutu 14.04 lts with fresh laravel project. My project name laravel and when I go to http://localhost/laravel/public/ I can see the laravel welcome page display, but when I create an url to test it didn't work.

    Route::get('test', function(){
      return 'It is work!!!';
});

I hope when I go to http://localhost/laravel/public/test | http://localhost/laravel/public/index.php/test it should display It is work!!! instead of this I get 404 Not Found nginx/1.4.6 (Ubuntu). I don't know what is wrong? I have php7 ubuntu 1.4.6 installed in my machine.

Here is nginx configuration->

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

root /usr/share/nginx/html;
index index.php index.html index.htm;

server_name localhost;

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

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
    try_files $uri /index.php =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index index.php;
    include fastcgi_params;
}

}

Please help me. I really thankful fro your help.

4
  • 2
    That's because the document root should point to the public directory, so it should be /usr/share/nginx/html/laravel/public and access it using http://localhost. This article explains it very well. Commented Apr 3, 2016 at 12:37
  • 1
    If you want to run multiple website on your nginx installation I suggest you use Virtual Hosts like http://laravel.local, not subdirectories like http://localhost/laravel. You can read this article which explains how easy it is to setup a virtual hosts. Commented Apr 3, 2016 at 12:41
  • Hi @Bogdan! I really thankful for your help :) Commented Apr 3, 2016 at 12:44
  • You're very welcome. Commented Apr 3, 2016 at 12:44

1 Answer 1

2

It looks like Bogdan already answered this in the comments. But for anybody else, make sure to point your document root to the /public directory of your Laravel project.

root /usr/you/laravelinstall/public;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.