远程服务器在ubuntu中返回了400个对apache2的错误请求


remote server returned 400 bad request for apache2 in ubuntu

我正在WPF中将文件上传到我的服务器。我没有显示这段代码,因为它适用于我的本地主机,所以我的服务器配置似乎不好。我的请求在这个php脚本中到达:

upload.php:

$target_dir = "/var/www/uploads/";
$target_file = $target_dir . $reg_id ."&".$to ."&". basename($_FILES["file"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, the file already exists.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error    
if ($_FILES['file']['error'] === UPLOAD_ERR_OK) { 
    if ($uploadOk == 0) {
        echo "Sorry, your file was not uploaded.";
    // if everything is ok, try to upload file
    } else {
        if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
            echo "The file ". basename( $_FILES["file"]["name"]). " has been uploaded.";
        } else {
            echo "Sorry, there was an error uploading your file to dir: $target_file.";
        }
    }
} else { 
    throw new UploadException($_FILES['file']['error']); 
} 
class UploadException extends Exception 
{ 
    public function __construct($code) { 
        $message = $this->codeToMessage($code); 
        parent::__construct($message, $code); 
    } 
    private function codeToMessage($code) 
    { 
        switch ($code) { 
            case UPLOAD_ERR_INI_SIZE: 
                $message = "The uploaded file exceeds the upload_max_filesize directive in php.ini"; 
                break; 
            case UPLOAD_ERR_FORM_SIZE: 
                $message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form";
                break; 
            case UPLOAD_ERR_PARTIAL: 
                $message = "The uploaded file was only partially uploaded"; 
                break; 
            case UPLOAD_ERR_NO_FILE: 
                $message = "No file was uploaded"; 
                break; 
            case UPLOAD_ERR_NO_TMP_DIR: 
                $message = "Missing a temporary folder"; 
                break; 
            case UPLOAD_ERR_CANT_WRITE: 
                $message = "Failed to write file to disk"; 
                break; 
            case UPLOAD_ERR_EXTENSION: 
                $message = "File upload stopped by extension"; 
                break; 
            default: 
                $message = "Unknown upload error"; 
                break; 
        } 
        echo $message;
        return $message; 
    } 
}     
?>

它正在工作,当我的文件小于2KB时,非常奇怪。。。所有更大的东西都被立即拒绝,并给出错误响应:

Error code: BadRequest
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at 192.168.99.1 Port 8080</address>
</body></html>
The uploaded file was only partially uploaded

那么我的错误可能在哪里呢?当远程服务器上的文件大于2KB,而不是localhost时,为什么我的请求无效?我在Docker中使用Apache2/PHP5和Ubuntu 14.04,我的php.ini:

post_max_size=1024M;upload_max_filesize=1024M;memory_limit=512M;

您也可以尝试在php中设置更高的内存限制吗?在php.ini 中

 memory_limit = 32M