自己配置 lnmp 运行 Laravel 出现了 403 Forbidden?

第一次在ubuntu16.04.4 LTS上自己安装nginx、mysql、php,
php的版本:

ubuntu@VM-0-17-ubuntu:/etc/nginx/sites-available$ php -v
PHP 7.1.15-1+ubuntu16.04.1+deb.sury.org+2 (cli) (built: Mar  6 2018 11:10:13) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.15-1+ubuntu16.04.1+deb.sury.org+2, Copyright (c) 1999-2018, by Zend Technologies

nginx版本:

ubuntu@VM-0-17-ubuntu:/etc/nginx/sites-available$ nginx  -v
nginx version: nginx/1.10.3 (Ubuntu)

下面是/etc/nginx/sites-available/default文件的内容的

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        #root /var/www/html;
        root /home/ubuntu/Code/blog/public;

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

        server_name _;

        location / {
         # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?$query_string;
        }
        location ~ \.php$ {
                fastcgi_pass   unix:/var/run/php/php7.1-fpm.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }
}

这是laravel5.1的目录结构,storage和bootstrap/cache目录应该是可写:
file

这是/var/log/nginx/error.log报的错:

2018/03/09 16:29:35 [error] 22528#22528: *3 directory index of "/home/ubuntu/Code/blog/public/" is forbidden, client: 112.80.38.102, server: _, request: "GET / HTTP/1.1", host: "119.27.182.170"

运行时报403错误。如果我修改了/etc/nginx/sites-available/default中的root /home/ubuntu/Code/blog/public;改成root /home/ubuntu/Code/index.php;就没问题。

请问有没有大神知道哪里出错了??

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
leo
最佳答案

index index.html index.htm index.nginx-debian.html;

改成

index index.php index.html index.htm index.nginx-debian.html;

6年前 评论
讨论数量: 2
leo

index index.html index.htm index.nginx-debian.html;

改成

index index.php index.html index.htm index.nginx-debian.html;

6年前 评论

@leo 强的一批,一直就没来注意这行,我以为有index.php呢。 感谢大神~

6年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!