【问题标题】:Heroku Nginx HTTP 413 entity too largeHeroku Nginx HTTP 413 实体太大
【发布时间】:2025-12-13 22:30:02
【问题描述】:

我在上传 4MB 文件时收到错误 413。我已经在public/ 文件夹中创建了一个.user.ini 文件。最多允许 10 MB 文件

所以我在我的nginx.conf 上使用了这样的client_max_body_size但我仍然得到 413。

location / {
    index index.php;
    try_files $uri $uri/ /index.php?$query_string;
    client_max_body_size 10M;
}

那个配置是​​因为我使用的是Laravel 5

这是我的Procfile

web: vendor/bin/heroku-php-nginx -C nginx.conf public/

我是不是做错了什么?

【问题讨论】:

    标签: heroku nginx laravel-5


    【解决方案1】:

    可能有点晚了,但为了解决这个问题,请将您的client_max_body_size 10M; 移出位置部分。像这样:

    client_max_body_size 10M;
    
    location / {
        index index.php;
        try_files $uri $uri/ /index.php?$query_string;
    }
    

    请参阅https://github.com/heroku/heroku-buildpack-php/blob/beta/conf/nginx/heroku.conf.php#L35,了解 heroku 如何包含此文件。

    【讨论】:

    • 你在哪里添加这些设置?
    • 无论您在哪里定义配置。如果您的 procfile 看起来像 web: vendor/bin/heroku-php-nginx -C nginx.conf public/ 那么它将是 nginx.conf