Lavarel project with nginx server return 404|Not Found but works fine with default /var/www/html root

I am using Digital Ocean VPS with a LEMP stack. I am struggling in the problem that return 404|not Found when accessing to my website. My lavarel project is stored as /var/www/html/api. It works fine with default /var/www/html root. My current config file is:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html/api/public;
    #root /var/www/html; //ok

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name ipaddress;
    client_max_body_size 64M;
    location / {

            try_files $uri $uri/ /index.php$is_args$args;
    location ~ \.php$ {

            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.2-fpm.sock;

Any help would be appreciative. Thanks a lot.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.


Question, have you checked the log files and can you also provide us with it ? Although I also suspect as @denislavgavrilov mentioned that this is a permissions problem.

Regards, Ivan

Hey, @py1210 ,

From what I can see, the nginx configuration seems perfectly fine. Could you please try and readjust the permissions for your Laravel projects with these:

sudo find /path/to/your/laravel/root/directory -type f -exec chmod 664 {} \;    
sudo find /path/to/your/laravel/root/directory -type d -exec chmod 775 {} \;

Also, please make sure to make the www-data owner of the directory:

sudo chown www-data:www-data /path/to/your/laravel/root/directory

I hope this helps and feel free to keep the conversation going!


Hi @denislavgavrilov , Thanks a lot for your detailed instruction. I followed your comment and below is the terminal output.

root@customize:/var/log/nginx# sudo find /var/www/html/api -type f -exec chmod 664 {} \;
root@customize:/var/log/nginx# sudo find /var/www/html/api -type d -exec chmod 775 {} \;
root@customize:/var/log/nginx# cd /var/www/html/api
root@customize:/var/www/html/api# sudo chgrp -R www-data storage bootstrap/cache
root@customize:/var/www/html/api# sudo chmod -R ug+rwx storage bootstrap/cache
root@customize:/var/www/html/api# ls -lrt
total 424
drwxrwxr-x 10 www-data www-data   4096 Jun 15 01:35 Modules
-rw-rw-r--  1 www-data www-data   1686 Jun 15 01:35 artisan
drwxrwxr-x  6 www-data www-data   4096 Jun 15 01:35 app
-rw-rw-r--  1 www-data www-data    537 Jun 15 01:35 webpack.mix.js
drwxrwxr-x  4 www-data www-data   4096 Jun 15 01:35 tests
drwxrwxr-x  5 www-data www-data   4096 Jun 15 01:35 storage
-rw-rw-r--  1 www-data www-data    563 Jun 15 01:35 server.php
drwxrwxr-x  2 www-data www-data   4096 Jun 15 01:35 routes
-rw-rw-r--  1 www-data www-data   1125 Jun 15 01:35 package.json
drwxrwxr-x  3 www-data www-data   4096 Jun 15 01:35 database
drwxrwxr-x  2 www-data www-data   4096 Jun 15 01:35 config
-rw-rw-r--  1 www-data www-data   2451 Jun 15 03:19 composer.json
drwxrwxr-x  3 www-data www-data   4096 Jun 15 04:16 bootstrap
drwxrwxr-x 71 www-data www-data   4096 Jun 15 04:42 vendor
-rw-rw-r--  1 www-data www-data 355447 Jun 15 04:42 composer.lock
drwxrwxr-x  2 www-data www-data   4096 Jun 16 01:04 public
root@customize:/var/www/html/api# tail -n 20 /var/log/nginx/error.log

Nothing appeared in last tail command.And the 404|Not Found stayed the same when accessing to the website. Thanks. Ny