开发异常在生产环境中显示 [英] Dev Exceptions are shown in production environment

查看:129
本文介绍了开发异常在生产环境中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个很大的问题,...并且在我的网站处于活动状态时不应该显示开发人员错误页面,我该怎么做以确保开发环境错误消息不在生产环境中出现?

I know this is a big NO NO... and should not be displaying developer error pages while my site is live, what can I do to ensure dev environment error messages are not appearing in production?

为什么出现这些?我以为在生产模式下默认关闭了它?我错过了设置吗?

Why are these appearing? I thought it was turned off by default when in production mode? Did I miss a setting?

注意:这是在共享服务器上。并且正在使用app.php而不是app_dev.php。

Note: This is on a shared server. And am using the app.php not app_dev.php.

当我在本地进入生产模式时,它会正确显示正确的错误消息(如下):

When I go to production mode locally it properly displays the right error messages (below):

糟糕!
发生错误服务器返回 404未找到。
东西坏了。请通过[电子邮件]给我们发送电子邮件,并让我们知道发生此错误时您正在做什么。我们将尽快修复它。很抱歉给您带来不便。

在实际网站上,它是否显示Symfony2开发环境错误消息?

Yet on the live site it's showing the Symfony2 dev environment error message?

我试图通过在app / Resource / TwigBundle / views / Exception中创建一个error404.html.twig文件来制作自定义错误消息,但它仍然没有加载该文件,并且只会显示开发人员错误消息。

I've tried to make a custom error message by making a error404.html.twig file in app/Resource/TwigBundle/views/Exception but it still doesn't load this file and just displays the developer error message.

推荐答案

在前端控制器中( web / app.php ),将创建 AppKernel 的实例。 AppKernel 继承了 Symfony的 Kernel 的构造函数,它需要两个参数:

In your frontend controller (web/app.php in the Symfony Standard Edition), an instance of AppKernel is created. AppKernel inherits the constructor from Symfony's Kernel, which requires two arguments:

/**
 * Constructor.
 *
 * @param string $environment The environment
 * @param bool   $debug       Whether to enable debugging or not
 */
public function __construct($environment, $debug)

$ environment 参数确定使用哪种配置( config_dev.yml config_prod.yml 等)。 $ debug 参数是启用或禁用调试的参数(因此确定是否显示异常)。

The $environment parameter only determines which configuration is used (config_dev.yml, config_prod.yml, etc.). The $debug parameter is the one that enables or disables debugging (and therefore determines wether exceptions are shown or not).

因此在 app.php 中,更改:

$kernel = new AppKernel('prod', true);

$kernel = new AppKernel('prod', false);

这应该用用户友好的错误页面替换详细的异常页面。

This should replace the detailed exception pages with user-friendly error pages.

这篇关于开发异常在生产环境中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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