Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache as Reverse Proxy for CouchDB

Tags:

I'm thinking of a web app that uses CouchDB extensively, to the point where there would be great gains from serving with the native erlang HTTP API as much as possible.

Can you configure Apache as a reverse proxy to allow outside GETs to be proxied directly to CouchDB, whereas PUT/POST are sent to the application internal logic (for sanitation, authentication...)? Or is this unwise -- the CouchDB built-in authentication options just seem a little weak for a Web App.

Thanks

like image 720
Overflown Avatar asked Aug 19 '09 06:08

Overflown


2 Answers

You can use mod_rewrite to selectively proxy requests based on the HTTP method.

For example:

# Send all GET and HEAD requests to CouchDB
RewriteCond %{REQUEST_METHOD} GET|HEAD
RewriteRule /db/(.*) http://localhost:5984/mydb/_design/myapp/$1 [P]

# Correct all outgoing Location headers
ProxyPassReverse /db/ http://localhost:5984/mydb/_design/myapp/

Any POST, PUT, or DELETE requests will be handled by Apache as usual, so you can wire up your application tier however you usually would.

like image 103
Avi Flax Avatar answered Oct 12 '22 09:10

Avi Flax


Your question is aging without answers, so I'll add this "almost answer".

Nginx can definitely redirect differently based on requests.

This is, if you are ready to place nginx in the front as the revproxy and place apache and couchdb both as backends.

like image 21
Christian Avatar answered Oct 12 '22 09:10

Christian