0

我在 symfony2.8 上有一个项目,我使用 Parrot OS(基于 Debian),我已经安装了 PHP7.1 和 MariaDB,但是当我尝试访问网站项目时,我得到了:

403 禁止

有一些日志:

/var/log/nginx/error.log

2018/08/18 19:57:29 [error] 2520#2520: *15 directory index of "/var/www/html/xxxxxx/" is forbidden, client: ::1, server: _, request: "GET /airnjobs/ HTTP/1.1", host: "localhost"

/var/log/nginx/access.log

::1 - - [18/Aug/2018:19:57:29 +0200] "GET /xxxxx/ HTTP/1.1" 403 199 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"

你能帮我吗:/我被卡住了!

更新 1:

仍然无法访问,我 chown 目录和文件和 chmod 没有结果。

4

1 回答 1

0

这看起来像是 nginx 配置问题,而不是权限问题。

如果/xxxxx是项目目录,则项目的 Web 根目录应为/xxxxx/web.
您的日志显示您正在尝试列出项目目录的内容,而您应该只访问/xxxxx/web/app_dev.php,/xxxxx/web/app.php/xxxxx/web/config.php
所以这个 403 错误是预期的行为。

尝试访问开发环境时,您的 URL 应该类似于
http://localhost/xxxxx/web/app_dev.php
或者http://xxxxx.local/app_dev.php如果您的网络主机配置正确。

symfony 文档有一个 2.8 的 nginx 配置示例:
https ://symfony.com/doc/2.8/setup/web_server_configuration.html#nginx

我对其进行了一些更改以适合您的情况:

server {
    server_name xxxxx.local;
    root /var/www/html/xxxxx/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }
    # DEV
    # This rule should only be placed on your development environment
    # In production, don't include this and don't deploy app_dev.php or config.php
    location ~ ^/(app_dev|config)\.php(/|$) {
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
    }
    # PROD
    location ~ ^/app\.php(/|$) {
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        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/xxxxx_error.log;
    access_log /var/log/nginx/xxxxx_access.log;
}

这将进入您的 nginx 配置文件,例如:
/etc/nginx/conf.d/xxxxx.conf

然后您需要将主机名添加xxxxx.local到您的/etc/hosts文件中:

127.0.0.1        xxxxx.local
于 2018-08-20T08:40:17.823 回答