Search code examples
phpproxycouchdbacraacralyzer

CouchDB reverse proxy


i installed couchdb on my root server. Now i'm trying to allow only PUT requests to my database via a proxy. But i can't get it working. What i tried:

(.htaccess)
SetEnvIf Request_URI acraproxy acraproxy
RequestHeader set Authorization "Basic base64credentials" env=acraproxy
RewriteEngine On
RewriteRule ^acraproxy/(.*)$ http://localhost:5984/mydatabase/_design/acra-storage/_update/report/$1 [P]

I always get a error code 405. I also tried to use php script like this:

<?php
$COUCH_INSTANCE = 'http://www.acmecouch.com'; // URL of your CouchDB instance
$COUCH_PORT = 80; // Port of your CouchDB instance
$REPORTER_USER = 'acra'; // Username of the reporter user
$REPORTER_PASSWORD = 'r3p0rts'; // Password for the reporter user
$APPNAME = 'myapp'; // the name of your app, same as defined when pushing your own acra-storage couchapp instance

if($_SERVER['REQUEST_METHOD'] === 'PUT') {
    $curl = curl_init($COUCH_INSTANCE.'/acra-'.$APPNAME.'/_design/acra-storage/_update/report/'.$_GET["reportid"]); 
    curl_setopt($curl, CURLOPT_PORT, $COUCH_PORT); 
    curl_setopt($curl, CURLOPT_USERPWD, $REPORTER_USER . ":" . $REPORTER_PASSWORD);
    curl_setopt($curl, CURLOPT_FAILONERROR, true); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_PUT, true);
    curl_setopt($curl, CURLOPT_INFILE, fopen("php://input","r"));
    curl_setopt($curl, CURLOPT_INFILESIZE, $_SERVER['CONTENT_LENGTH']); 
    $result = curl_exec($curl); 
    echo $result;
} else {
    // If not a PUT request, just get the root of the CouchDB.
    // This allows to check with a browser that the path from your php server
    // to the couch instance is operational.
    $curl = curl_init($COUCH_INSTANCE); 
    curl_setopt($curl, CURLOPT_FAILONERROR, true); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    $result = curl_exec($curl); 
    echo $result;
} 
?>

But that fails with php error:

CURLOPT_FOLLOWLOCATION 
cannot be activated when an open_basedir is set

I followed this tutorial: https://github.com/ACRA/acralyzer/wiki/Setting-up-a-reverse-proxy

Can someone help me with this?


Solution

  • Ok i found the problem myself: A apache module was missing (submodule of proxy). Now above solutions work flawless.