skip to Main Content

I have a fastcgi++ service. It takes 4 parameters through POST because one of them is a password. My sample input is 61 characters. This is how I am calling my service:

curl --data 'name=test&address=abc&phoneNumber=0987654321&password=test123' http://localhost/cgi-bin/add-user.fcg

I get this error: 413 Request Entity too large. Based on my research I found that it means apache was expecting a smaller body than it got. So, I added LimitRequestBody 0 to httpd.conf (I am not in production environment). But apache still complains that the request entity is too large.

I added -v to curl and this is the output:

*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 80 (#0)
> POST /cgi-bin/add-user.fcg HTTP/1.1
> Host: localhost
> User-Agent: curl/7.61.1
> Accept: */*
> Content-Length: 60
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 60 out of 60 bytes
< HTTP/1.1 413 Request Entity Too Large
< Date: Sun, 24 Mar 2019 03:48:09 GMT
< Server: Apache/2.4.38 (Fedora) mod_fcgid/2.3.9
< Connection: close
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=utf-8
< 
* Closing connection 0
<!DOCTYPE html><html lang='en'><head><title>413 Request Entity Too Large</title></head><body><h1>413 Request Entity Too Large</h1></body></html>

This is my httpd.conf:

ServerRoot "/etc/httpd"

Listen 80

Include conf.modules.d/*.conf

User apache
Group apache

ServerAdmin root@localhost

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/var/www/html"

<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks

    AllowOverride None

    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
    LogFormat "%h %l %u %t "%r" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i" %I %O" combinedio
    </IfModule>


    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options +ExecCGI
    Require all granted
    SetHandler fcgid-script
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on

IncludeOptional conf.d/*.conf

#I added the line below
LimitRequestBody 0 

This it the fcgid.conf:

AddHandler fcgid-script fcg fcgi fpl

Sane place to put sockets and shared memory file
FcgidIPCDir /run/mod_fcgid
FcgidProcessTableFile /run/mod_fcgid/fcgid_shm

2

Answers


  1. Chosen as BEST ANSWER

    I should have mentioned that I was using the fastcgi++ library. As @covener mentioned, the 413 page was not apache's. It turns out that it was fastcgi++. I should have read the docs first. It clearly mentions here that POST is not enabled by default. Adding a constructor to my class and calling the Request constructor with the max size of POST requests I wanted, solved the problem.

    P.S. thanks a lot @hansherik for all the hours of debugging you have done for me.


  2. (not an answer, but too big for a comment)

    what do you get if you run this php script?

    <?php
    declare(strict_types=1);
    header("Content-Type: text/plain;charset=utf-8");
    $ch=curl_init('http://localhost/cgi-bin/add-user.fcg');
    curl_setopt_array($ch,array(CURLOPT_USERAGENT=>'curl/7.61.1',CURLOPT_RETURNTRANSFER=>1));
    $post_str="";
    for($i=0;$i<61;++$i){
    curl_setopt_array($ch,array(
    CURLOPT_POST=>1,
    CURLOPT_POSTFIELDS=>$post_str,
    ));
    curl_exec($ch);
    $code=curl_getinfo($ch,CURLINFO_RESPONSE_CODE);
    echo "bytes: {$i} code: {$code}n";
    $post_str.="a";
    }
    curl_close($ch);
    echo "finished loop";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search