• We value your experience with Plesk during 2024
    Plesk strives to perform even better in 2025. To help us improve further, please answer a few questions about your experience with Plesk Obsidian 2024.
    Please take this short survey:

    https://pt-research.typeform.com/to/AmZvSXkx
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Issue 502 Gateway error with HTTP POST Requests but not GET requests

AlanUK

New Pleskian
Server operating system version
Linux 4.19.0
Plesk version and microupdate number
Version 18.0.61 Update #5
I am setting up a new plesk webserver and moving some websites from an existing plesk webserver which has been running for about five years with no problems. All was going well until I started hitting strange 502 Gateway errors, Narrowing this down, I found it seems to be connected with whether I am using HTTP GET or POST requests. To demonstrate this problem, I am using this minimalist perl program:

test.cgi

#!/usr/bin/perl
print "Content-Type: text/html\n\n" ;
print "<p>Hello World\n" ;
exit ;

Running it from the browser address bar works fine, the permissions are set to 0755, there is a handler set up in the Apache config for cgi-script .cgi and so on. When I run it by typing the address directly into the browser I get Hello World just as expected. I can also run it from a HTML form using GET, like this:

<!DOCTYPE HTML>
<html lang=EN>
<body>
<h1>Testing with GET</h1>
<form class=modern action="test.cgi" method=GET>
<button type=submit>Submit form using GET</button>
</form>
</body>
</html>

but if I change that HTML page to use POST, like this,

<!DOCTYPE HTML>
<html lang=EN>
<body>
<h1>Testing with POST</h1>
<form action="test.cgi" method=POST enctype="multipart/form-data">
<button type=submit>Submit form using POST method</button>
</form>
</body>
</html>

Then it instantly comes up with 502 Bad Gateway and the proxy_error_log says

upstream prematurely closed connection while reading response header from upstream, client: ...., server: www......co.uk,
request: "POST /test/test.cgi HTTP/2.0",
upstream: "https://127.0.0.1:7081/test/test.cgi",
host: "www.....co.uk",
referrer: "https://www.....co.uk/test/test2.shtml"

So it is the exact same program, zero complexity, and the only difference is the HTTP method used. I have tried it with the other enctypes for the post method with the same results. What am I missing? Is there a firewall web rule somewhere that I need to disable, or an nginx setting? It would be much appreciated if anyone has any ideas on this and can point me to whatever Plesk setting I need to tweak.
 
FURTHER INFORMATION ON THIS 502 GATEWAY ERROR:

Further testing of the above revealed that this simple program generated the same error on both the older plesk system and the new one I am setting up, whereas other, more complicated programs, work correctly using POST on both systems. Surprisingly, I was able get to simple test to work by generating more output. Changing

print "<p>Hello World\n" ;

to

print "<p>Hello World Hello World Hello World Hello World Hello World\n" ;

meant that suddenly everything worked as expected. Further trial and error established that outputting 70 characters of data in the print statements allowed the POST request to work fine, but 69 characters or less of output generates a 502 Gateway error. This is only the case when the URL is requested using POST requests. Using the GET method for the same URL doesn't have this restriction. This is regardless of the amount of data posted to the URL. Whether you post zero bytes or kilobytes, it will work or fail depending upon the amount of data output by the target script.

This does not appear to be a timing issue. If I add a long processing loop to the test script but do not change the amount of data output, the POST still fails in the same way.

It also does not apepar to be an issue linked to the total amount of data served. If I output extra HTTP headers in the HTTP script, the script still fails unless there is at least 70 characters of content in the body of the response.

Can anyone else replicate this result?

I do not know if this is by accident or design, but I've never heard of this limitation before. Is it a bug in the nginx code, or is it a logical shortcut, made on the assumption that post requests will always have a certain minimum amount of data?

It is is easy enough to work around, now that I am aware of this limitation, but it would at least help to know if it is always this magic number of bytes, or is it just some random value which just happens to be 70 at the moment, or is it all linked to some other setting or a firewall rule which is causing this?

Any clarification would be greatly apppreciated.
 
Apologies everyone, this should have been posted in Plesk Obsidian for Linux, not Windows. I don't know if the same issue arises on other versions, but at this time I have only been using Linux. Unfortunately, I cannot see a way to move this thread to the correct forum.
 
Welcome to the forum. I've moved your post to Plesk Obsidian for Linux.

From the "Linux 4.19.0", I guess you're running Debian?

I think the easiest way to solve this, is to use the correct PHP handler, the "FPM application served by Apache".
After that, correct the file permissions, 644 for files and 755 for directories.
 
Back
Top