Symfony2网站没有返回404错误

时间:2016-08-22 20:52:12

标签: apache symfony

如果我尝试访问我网站上任何不存在的资源(例如example.com/this/path/does/not/exist或example.com/images/fakeimage.jpg),它就不会# 39; t返回404错误。它只是在超时之前挂起大约一分钟,同时它最大化了服务器上的CPU和RAM。

我认为它可能是.htaccess文件,但它与默认的Symfony相同。

我的另一个想法是,我的Apache Vhost文件可能存在问题,但我有另一个Symfony网站,使用相同的配置/不同的网站名称运行没有问题。

此时调试我有点不知所措。关于我还能看到什么的任何想法?

- 编辑 - 我在日志中找到了这个:

request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /this/is/not/a/path"" at /var/www/dev/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php line 176 {"exception":"[object] (Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException(code: 0): No route found for \"GET /this/is/not/a/path\" at /var/www/dev/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php:176, Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException(code: 0):  at /var/www/dev/app/cache/prod/appProdUrlMatcher.php:2209)"} []

其次是100个:

[2016-08-22 15:26:10] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException: "The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL." at /var/www/dev/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authorization/AuthorizationChecker.php line 57 {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AuthenticationCredentialsNotFoundException(code: 0): The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL. at /var/www/dev/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authorization/AuthorizationChecker.php:57)"} []

我读到这可能与Symfony中的security.yml有关。以下可能有什么不妥之处吗?

firewalls:
        secured_area:
            pattern: ^/
            switch_user: { role: ROLE_SUPER_ADMIN, parameter: _switch_user }
            oauth:
                failure_path: "/login"
                login_path: "/login"
                check_path: /connect_check
                provider: fos_userbundle
                resource_owners:
                    facebook: "/login/check-facebook"
                    google: "/login/check-google"
                oauth_user_provider:
                    service: app.provider.oauth
            anonymous: true

        form_login:
            provider: fos_userbundle
            check_path: fos_user_security_check
            login_path: fos_user_security_login
            csrf_provider: security.csrf.token_manager
            use_referer: true

        logout:
            path: fos_user_security_logout
            target: fos_user_security_login
            success_handler: cps.sso.security.logout_success_handler
            invalidate_session: false

        access_denied_url: /
access_control:

    - { path: ^/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: new$, role: ROLE_ADMIN}
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/homerecalls$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: $/reports-login, role: IS_AUTHENTICATED_ANONYMOUSLY}
    - { path: ^/article/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/category/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/author/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/accounts/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/photo/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/fileupload/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/services/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/company/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resources/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/agents/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/sellers/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/buyers/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: ROLE_ADMIN }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/, role: ROLE_ADMIN }
    - { path: ^/user/, role: [ROLE_USER, ROLE_ADMIN]}
    - { path: ^/profile/, role: [ROLE_USER, ROLE_ADMIN]}

1 个答案:

答案 0 :(得分:0)

好的,我找到了解决方案,但我怀疑很多其他人实际上会因为我做的事情而遇到这个问题。这篇文章让我走上正确的道路来修复它。 Symfony2 error 500 instead of 404 at production

我正在查看这篇帖子并结合我得到的一些错误,并意识到几个月前我第一次学习Symfony时,我试图在我的config.yml中使用这个在生产服务器上启用Symfony Profiler :

profiler:
    matcher:
        service: app.super_admin_matcher

,这在AppBundle / Profiler / SuperAdminMatcher.php中:

<?php

namespace AppBundle\Profiler;

use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;

class SuperAdminMatcher implements RequestMatcherInterface
{
    protected $authorizationChecker;

    public function __construct(AuthorizationCheckerInterface $authorizationChecker)
    {
        $this->authorizationChecker = $authorizationChecker;
    }

    public function matches(Request $request)
    {
        return $this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN');
    }
}

?>

一旦我删除了我现在不需要的代码,一切都开始像魅力了一样。