Laravel现有项目到NGINX服务器“权限被拒绝”404浏览器错误

时间:2017-10-16 17:34:53

标签: php nginx laravel-5

我已经使用Nginx和Laravel设置了一个新的LEMP服务器。所有正确的设置和2个新的默认laravel项目运行良好。现在我准备好了,并希望从其他服务器添加我现有的2个laravel项目。但是我总是在重定向到登录页面后从浏览器中获得Nginx的404错误(如果我从公共文件夹输入地址和端口,则会自动)。脚本在其他服务器上运行良好,它只能是来自“Laravelproject/storage”或其他的Permission文件夹错误,我认为。

我尝试了很多东西,从缓存清理和重新启动nginx,php并检查所有文件夹权限,现在都是777,是的我知道它不安全但我总是在我的nginx中出现“Permission denied”错误error.log档案。

这里我总是在日志文件中得到错误:

 [error] 29564#0: *16 directory index of "/var/www/html/project/" is forbidden, client: ::1, server: localhost, request: "GET /project/ HTTP/1.1", host: "localhost"

PHP message: PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/html/project/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied' in /var/www/html/project/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107

    [error] 28854#0: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/html/project/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied' in /var/www/html/project/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107

最大的错误是laravel.log,但它现在有777个权限。

我的nginx配置:

server {
    listen 7171 ;
    listen [::]:7171;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html/project/public;

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

    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }



    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}

我也不能用

运行项目
php artisan serve

我收到此错误:

  [ErrorException]                                   
  passthru() has been disabled for security reasons 

但我不认为这是一个问题,它只是现在阻止它的nginx。

有什么想法吗?我现在已经在这个项目上工作了几个月,现在非常令人沮丧....我现在24小时在谷歌上搜索并尝试我找到的所有没有结果的东西。我使用的是Laravel 5.4。之前的服务器是apache而不是nginx。

1 个答案:

答案 0 :(得分:0)

解决方案!编辑此行:

 #try_files $uri $uri/ =404;

并添加

 try_files $uri $uri/ /index.php;

示例:

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;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }