donglugou6652 2016-09-22 21:13
浏览 488
已采纳

允许Laravel响应403而不是nginx

I am trying to have Laravel respond a custom 403 error rather than display the default nginx forbidden page.

I have custom handlers for most of my exception types in app/Exceptions/Handler.php and they are working just fine, except for 403. I added the following code to the Handler.php file within the render function to handle 403:

if($e instanceof HttpException && $e->getStatusCode() == 403){
        return response("403 Forbidden error response");
    }

but I still just see the default nginx forbidden page if I lets say navigate to http://myapp.com/images/

At this point I am fairly certain this is an nginx config I may be missing, but am not 100% sure what and after searching the web can't seem to find the solution.

Thanks

  • 写回答

2条回答 默认 最新

  • duanjie3267 2016-09-23 17:46
    关注

    Thanks for the advice and reviews everyone, I have been able to find and fix what was causing the issue. As Elias Soares mentioned above in comment, the issue was obviously happening before Laravel was even reached. I went into my nginx config file and noticed the following line:

    error_page 404 /index.php;
    

    and since Laravel was indeed correctly handling 404 errors, I simply added the exact same thing for 403:

    error_page 403 /index.php;
    

    and now Laravel is handling any 403 errors the way I wanted it to do.

    Thanks!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料