couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [11/32] git commit: updated refs/heads/1781-reorganize-and-improve-docs to 11fd32a
Date Fri, 14 Jun 2013 08:25:08 GMT
Improve vhosts config docs using CouchDB sources.


Branch: refs/heads/1781-reorganize-and-improve-docs
Commit: 12d6511f25c0fd669d833090724e13d0e6cb5d53
Parents: e93f3d3
Author: Alexander Shorin <>
Authored: Tue Jun 11 20:02:05 2013 +0400
Committer: Alexander Shorin <>
Committed: Tue Jun 11 21:28:43 2013 +0400

 share/doc/src/config/httpd.rst  | 14 ++++++++++++
 share/doc/src/config/vhosts.rst | 44 ++++++++++++++++++++++++++++--------
 2 files changed, 49 insertions(+), 9 deletions(-)
diff --git a/share/doc/src/config/httpd.rst b/share/doc/src/config/httpd.rst
index 2996add..441b100 100644
--- a/share/doc/src/config/httpd.rst
+++ b/share/doc/src/config/httpd.rst
@@ -209,3 +209,17 @@ whitelist::
   config_whitelist = [{httpd,config_whitelist}, {log,level}, {etc,etc}]
+.. _config/httpd/redirect_vhost_handler:
+``redirect_vhost_handler`` :: Virtual Hosts custom redirect handler
+This option allows to change the default function that handles requests to
+:ref:`virtual hosts <config/vhosts>`::
+  [httpd]
+  redirect_vhost_handler = {Module, Fun}
+Specified function take 2 arguments: the Mochiweb request object and the target
diff --git a/share/doc/src/config/vhosts.rst b/share/doc/src/config/vhosts.rst
index 6140012..719e143 100644
--- a/share/doc/src/config/vhosts.rst
+++ b/share/doc/src/config/vhosts.rst
@@ -22,24 +22,24 @@ even if they arrive on the some inbound IP address.
 This allows different virtual hosts on the same machine to map to different
 databases or design documents, etc. The most common use case is to map a
-virtual host to a Rewrite Handler, to provide full control over the
-application's URIs.
+virtual host to a :ref:`Rewrite Handler <api/ddoc/rewrite>`, to provide full
+control over the application's URIs.
-To add a virtual host, add a CNAME pointer to the DNS for your domain
+To add a virtual host, add a `CNAME` pointer to the DNS for your domain
 name. For development and testing, it is sufficient to add an entry in
 the hosts file, typically `/etc/hosts`` on Unix-like operating systems:
 .. code-block:: text
    # CouchDB vhost definitions, refer to local.ini for further details
-       sofa.couchdb
+       couchdb.local
 Test that this is working:
 .. code-block:: bash
-   $ ping -n 2 sofa.couchdb
-   PING sofa.couchdb ( 56(84) bytes of data.
+   $ ping -n 2 couchdb.local
+   PING couchdb.local ( 56(84) bytes of data.
    64 bytes from localhost ( icmp_req=1 ttl=64 time=0.025 ms
    64 bytes from localhost ( icmp_req=2 ttl=64 time=0.051 ms
@@ -47,10 +47,36 @@ Finally, add an entry to your :ref:`configuration file <config>`
in the
 ``[vhosts]`` section::
-  sofa.couchdb:5984 = /sofa/_design/sofa/_rewrite
+  couchdb.local:5984 = /example
+  *.couchdb.local:5984 = /example
 If your CouchDB is listening on the default HTTP port, or is sitting
 behind a proxy, then don't specify a port number in the `vhost` key.
-With the above setup, a request to ``http://sofa.couchdb:5984/sweet-o``
-will be mapped to ````
+The first line will rewrite the request to display the content of the `example`
+database. This rule works only if the ``Host`` header is ``couchdb.local`` and
+won't work for `CNAMEs`. Second rule on the other hand match all `CNAMEs` to
+`example` db. So `www.couchdb.local` or `db.couchdb.local` will work.
+.. _config/vhosts/rewriting:
+Rewriting Hosts to path
+Like in the :ref:`_rewrite <api/ddoc/rewrite>` handler you could match some
+variable and use them to create the target path. Some examples::
+  [vhosts]
+  *.couchdb.local = /*
+  :dbname. = /:dbname
+ = /:dbname/_design/:ddocname/_rewrite
+First rule pass wildcard as `dbname`. The second one does the same, but uses a
+variable name. And the third one allows you to use any app with `ddocname` in
+any database with `dbname`.
+You could also change the default function to handle request by changing
+the setting :ref:`redirect_vhost_handler <config/httpd/redirect_vhost_handler>`
+in :ref:`httpd <config/httpd>` config section.

View raw message