Symfony2 开发环境有效,生产环境给出 404 错误 [英] Symfony2 dev environment works, prod environment gives 404 error

查看:30
本文介绍了Symfony2 开发环境有效,生产环境给出 404 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在我的机器上成功安装了 Symfony2.

I have recently successfully installed Symfony2 on my machine.

我可以访问http://localhost/app_dev.php(开发环境)

I can access http:/localhost/app_dev.php (dev environment)

但是,当我尝试访问 prod 环境时:

However, when I try to access the prod environment:

http://localhost/app.php

我在浏览器中收到以下错误消息:

I get the following error message in the browser:

糟糕!发生错误

服务器返回404 Not Found".东西坏了.请通过 [email] 给我们发电子邮件,让我们知道什么发生此错误时您正在执行操作.我们会尽快修复可能的.给您带来的不便,敬请谅解.

The server returned a "404 Not Found". Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.

我已经检查了明显的:文件 app.php 确实与 app_dev.php 存在于同一文件夹中 - 所以我不知道是什么导致了这种情况.

I have checked the obvious: The file app.php does exist in the same folder as app_dev.php - so I don't know whats causing this.

有没有人有办法解决这个问题?

Does anyone have a solution to fix this?

[]

我已按照建议键入:sudo php app/console cache:clear env=prod no-debug 清除了缓存.我现在得到一个空白屏幕.令人担忧的是,app/logs/prod.log 中没有记录任何错误消息,所以我对出了什么问题一无所知(prod 环境仍然可以正常工作).

I have cleared the cache by typing: sudo php app/console cache:clear env=prod no-debug as recommended. I now get a blank screen. Worryingly, there are no error messages logged in app/logs/prod.log, so I have not got the faintest idea as to what is wrong (prod environment still works just fine).

我的 app/config/routing.yml 文件的内容:

Contents of my app/config/routing.yml file:

### 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 文件

Here is my app/config/routing_dev.yml file

_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**

I just noticed that I DO NOT have a routing_prod.yml**

(警铃响起)- Symfony2 不附带生产路由配置文件吗?

(alarm bells ringing) - does Symfony2 not ship with a production routing config file?

我的Apache配置文件内容如下图:

My Apache configuration file content is shown below:

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 的内容

Contents of app/logs/prod.log

[2012-08-10 18:10:38] security.INFO:用一个匿名令牌 [] [] [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 行 [] []

[2012-08-10 18:10:38] security.INFO: Populated SecurityContext with an anonymous Token [] [] [2012-08-10 18:10:38] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /" (uncaught exception) at /path/to/symfony/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/EventListener/RouterListener.php line 83 [] []

推荐答案

你有没有打开生产环境并清除缓存?运行控制台并执行以下操作:

Have you turned on the production environment and cleared the cache? Run the console and do this:

app/console --env=prod cache:clear

这篇关于Symfony2 开发环境有效,生产环境给出 404 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆