我可以访问
http:/localhost/app_dev.php
(开发环境)。然而,当我尝试访问生产环境时:
http:/localhost/app.php
我在浏览器中收到以下错误消息:"Oops! An Error Occurred",服务器返回了 "404 Not Found"。某些地方出了问题。请发送电子邮件至[email]告诉我们您遇到此错误时正在做什么。我们将尽快修复。对于任何造成的不便,我们深感抱歉。
我已检查过显而易见的:文件app.php与app_dev.php位于同一文件夹中 - 所以我不知道是什么原因导致了这个问题。
有人有解决方法吗?
[[编辑]]
我已通过输入以下内容清除缓存:sudo php app/console cache:clear env=prod no-debug,建议这样做。现在我得到了一个空白屏幕。令人担忧的是,没有错误消息记录在app/logs/prod.log中,所以我对出了什么问题毫无头绪(生产环境仍然正常工作)。
我的app/config/routing.yml文件的内容:
### fos routing, remove later
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
###
# Internal routing configuration to handle ESI
#_internal:
# resource: "@FrameworkBundle/Resources/config/routing/internal.xml"
# prefix: /_internal
这是我的app/config/routing_dev.yml文件
_welcome:
pattern: /
defaults: { _controller: AcmeDemoBundle:Welcome:index }
_demo_secured:
resource: "@AcmeDemoBundle/Controller/SecuredController.php"
type: annotation
_demo:
resource: "@AcmeDemoBundle/Controller/DemoController.php"
type: annotation
prefix: /demo
_assetic:
resource: .
type: assetic
_wdt:
resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix: /_wdt
_profiler:
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
_configurator:
resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
prefix: /_configurator
_main:
resource: routing.yml
我刚刚注意到我没有一个routing_prod.yml文件。(警钟鸣响)Symfony2没有提供生产环境的路由配置文件吗?
下面是我的Apache配置文件内容:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /path/to/symfony/web
ServerName localhost
# Custom log file
Loglevel warn
ErrorLog /path/localhost.error.log
CustomLog /path/localhost.access.log combined
<Directory /path/to/symfony/web>
AllowOverride None
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</Directory>
</VirtualHost>
[[更多细节]]
app/logs/prod.log的内容
[2012-08-10 18:10:38] security.INFO: 使用匿名Token填充SecurityContext [] [] [2012-08-10 18:10:38] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: 找不到路由 "GET /" (未捕获异常) 在 /path/to/symfony/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/EventListener/RouterListener.php 的第83行 [] []
app/config/routing.yml
文件吗? - Vitalii Zurianrouting_dev.yml
和routing_prod.yml
。我认为您应该检查 Web 服务器的access.log
和error.log
。另外,请附上您的 Web 服务器虚拟主机配置。 - Vitalii Zurianrouting_prod.yml
也没关系。这意味着它会选择routing.yml
。 - Vitalii Zurianrm -rf app/cache/*
),然后运行app/console router:debug
命令来查看已注册的路由信息。 - kgilden