【发布时间】:2012-08-05 10:36:35
【问题描述】:
我最近在我的机器上成功安装了 Symfony2。
我可以访问http:/localhost/app_dev.php(开发环境)
但是,当我尝试访问 prod 环境时:
http:/localhost/app.php
我在浏览器中收到以下错误消息:
糟糕!发生错误
服务器返回“404 Not Found”。 东西坏了。请在 [email] 给我们发电子邮件,让我们知道什么 发生此错误时您正在做的事情。我们会尽快修复 可能的。给您带来的不便,我们深表歉意。
我已经检查了明显的:文件 app.php 确实存在于与 app_dev.php 相同的文件夹中 - 所以我不知道是什么原因造成的。
有没有人可以解决这个问题?
[[编辑]]
我已按照建议键入:sudo php app/console cache:clear env=prod no-debug 清除了缓存。我现在得到一个空白屏幕。令人担忧的是,app/logs/prod.log 中没有记录任何错误消息,所以我对出了什么问题一无所知(prod 环境仍然可以正常工作)。
我的 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:填充的 SecurityContext 带有 匿名令牌 [] [] [2012-08-10 18:10:38] 请求。错误: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: 没有路由 在“GET /”(未捕获的异常)中找到 /path/to/symfony/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/EventListener/RouterListener.php 第 83 行 [] []
【问题讨论】:
-
你能粘贴你的
app/config/routing.yml吗? -
还有
routing_dev.yml和routing_prod.yml。我还认为您应该检查您的网络服务器的access.log和error.log。另外,请附上您的网络服务器虚拟主机配置。 -
没有
routing_prod.yml也没关系。这意味着它将选择routing.yml -
您也可以尝试手动删除缓存目录 (
rm -rf app/cache/*) 并运行app/console router:debug以查看已注册的确切路由。 -
我遇到了同样的问题,现在我在空白页面,没有像你这样的错误,那么你找到解决方案了吗?