403禁止使用nginx/1.4.6(Ubuntu) - Laravel

kyo*_*kyo 20 php nginx laravel ubuntu-12.04 laravel-5.1

我一直在 403 Forbidden

在此输入图像描述


我的设置:

/etc/nginx/sites-available/default

默认

server {
        listen   80;


        root home/laravel-app/;

        index index.php index.html index.htm;

        server_name example.com;

        location / {
                try_files $uri $uri/ /index.html;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;
        }

        # pass the PHP scripts to FastCGI server listening on the php-fpm socket
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

        }

}
Run Code Online (Sandbox Code Playgroud)

更新

我按照这个指示:这里


任何关于此的提示/建议都将是一个巨大的帮助!

Ben*_*rne 15

您需要为root指令指定绝对路径.Nginx使用--prefix开关在编译时设置目录.默认情况下这是/usr/local/nginx.

这意味着您的root目前设置为root home/laravel-app/会导致nginx查找/usr/local/nginx/home/laravel-app/可能不在您文件所在位置的文件.

如果将root指令设置为绝对路径(如/var/www/laravel-app/public/nginx),则会找到这些文件.

同样,你会注意到我添加/public/到上面的路径.这是因为Laravel在那里存储了它的index.php文件.如果您只是指向/laravel-app/那里没有索引文件,它会给你403.

  • 另外,我多次犯的错误就是忘记从我的laravel项目的根目录运行`php artisan key:generate`.如果未设置`APP_KEY`环境变量,即使nginx配置正确,也可能出现403错误. (2认同)