【问题标题】:Debian Jessie Nginx 1.8.0 Symfony 3 returning 500 responseDebian Jessie Nginx 1.8.0 Symfony 3 返回 500 响应
【发布时间】:2016-06-26 21:01:35
【问题描述】:

我已经在我的本地计算机上设置了一个 Symphony 3 站点,它可以工作。然后我将它上传到我的服务器,这是一个 Debian Jessie 服务器,上面设置了 Nginx 1.8 和 PHP 7。

当我尝试访问该网站时,我收到以下错误

api.server.com 当前无法处理此请求。 HTTP 错误 500

当我查看错误日志时,我得到以下信息:

2016/06/26 20:45:03 [error] 28099#0: *1 FastCGI sent in stderr: "PHP 

message: PHP Fatal error:  Uncaught UnexpectedValueException: The stream or file "/var/www/aqua_note/var/logs/prod.log" could not be opened: failed to open stream: Permission denied in /var/www/aqua_note/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:97
Stack trace:
#0 /var/www/aqua_note/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)
#1 /var/www/aqua_note/vendor/monolog/monolog/src/Monolog/Handler/FingersCrossedHandler.php(112): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#2 /var/www/aqua_note/vendor/monolog/monolog/src/Monolog/Logger.php(336): Monolog\Handler\FingersCrossedHandler->handle(Array)
#3 /var/www/aqua_note/vendor/monolog/monolog/src/Monolog/Logger.php(643): Monolog\Logger->addRecord(500, 'Uncaught PHP Ex...', Array)
#4 /var/www/aqua_note/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php(89): Monolog\Logger->critical('Uncaught PHP Ex...', Array)
#5" while reading response header from upstream, client: 108.46.158.41, server: api.servername.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "api.servername.com"

我的 nginx 服务器配置

server {
    server_name api.servername.com;
    root /var/www/aqua_note/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }

    # PROD
    location ~ ^/app\.php(/|$) {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/app.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

    # return 404 for all other php files not matching the front controller
    # this prevents access to other php files you don't want to be accessible.
    location ~ \.php$ {
      #return 404;
    }

    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
}

任何人都可以就我做错了什么提供一些帮助吗?

【问题讨论】:

    标签: nginx debian symfony php-7


    【解决方案1】:

    看来您需要正确设置权限:

    http://symfony.com/doc/current/book/installation.html#checking-symfony-application-configuration-and-setup

    做这样的事情:

    $ HTTPDUSER=`ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1`
    $ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var
    $ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var
    

    从 Symfony3 安装目录。 httpd 用户需要对 var 目录的权限。在你的情况下,用户可能是“nginx”,我不确定。

    【讨论】:

    • 我如何知道哪个用户?是 www-data 这是对 /var/www 文件夹具有权限的用户
    • 第一个命令确定并将其存储在变量 HTTPDUSER 中,因此请尝试运行上述命令,看看会发生什么。
    • 我在网上做了一个快速搜索,用户应该存储在nginx.conf文件中,如下所示:user nginx; 但它可能会有所不同。
    • 非常感谢,我做错了什么让我发疯了
    • 好消息!很高兴能帮忙!
    猜你喜欢
    • 2018-02-24
    • 1970-01-01
    • 1970-01-01
    • 2016-10-20
    • 1970-01-01
    • 1970-01-01
    • 2017-10-22
    • 1970-01-01
    • 2016-02-25
    相关资源
    最近更新 更多