incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hendrik Jan van Meerveld <haa...@gmail.com>
Subject Re: Redirect the welcome page without breaking Futon?
Date Wed, 13 Apr 2011 12:50:10 GMT
Hello Sean,

I decided not to use _rewrite and vhost because all links and ajax in my
application should then be rewritten.

Therefore I returned to my original setup with nginx as a reverse proxy.
I need nginx anyway because I want to protect one design element from being
read and replicated.

For those who want to protect parts of their design from being read; this is
the setup I used in Nginx.
(etc/nginx/sites-available/default)
Also this setup redirects people to another welcome page instead of "
{"couchdb":"Welcome","version":"1.0.1"}".

The *_design/main* is the design that I want nobody to read. I use another
design *_design/manage*
which is accessed from the first if users want to log in.
*_design/manage*is not protected from being read.


- First "server" block: If someone goes to *www.domain.net/something* from
the internet, this is through port 80.
If someone goes to *www.domain.net/* (without something) then he/she will be
redirected to my welcome page.

- Second "server" block: If I want to use Futon, this does not work
correctly via *www.domain.net/_utils*, but with this second
server block I can go to *www.domain.net:81/_utils* to use Futon. (The
difference is a missing redirect and listen [::]:81;)

server {
 server_name localhost www.domain.net domain.net;
 listen [::]:80;

 location =/db/_design/main {
return 444;
 }

 location =/db/_design/main/ {
return 444;
 }

 location /db/_design/main/_view/ {
return 444;
 }

 location =/ {
rewrite ^ /db/_design/main/_show/show/welcome;
 }

 location / {
proxy_pass http://localhost:5984;
 proxy_redirect off;
proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 }

}

server {
 server_name _;
listen [::]:81;

location =/db/_design/main {
 return 444;
}

location =/db/_design/main/ {
 return 444;
}

location /db/_design/main/_view/ {
 return 444;
}

location / {
 proxy_pass http://localhost:5984;
 proxy_redirect off;
proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 }

}


Kind regards,
Hendrik Jan

On 12 April 2011 18:44, Sean Copenhaver <sean.copenhaver@gmail.com> wrote:

> Glad I could help. If you get the kinks worked out it would be great if you
> post some information about your final solution. I would imagine others
> will
> find it useful (including me) one day.
>
> On Tue, Apr 12, 2011 at 12:32 PM, Hendrik Jan van Meerveld <
> haaiee@gmail.com
> > wrote:
>
> > Thank you Sean,
> >
> > I just tried it: it works!
> >
> > The rewrite should actually be:
> > {
> >  "from" : "*",
> >  "to" : "_show/show/welcome"
> > }
> >
> > And I need to do a lot of fine-tuning, but the first results look
> > promising.
> > Also need to put futon.domain.com in my hosts file I suppose.
> >
> > Kind regards,
> > Hendrik Jan
> >
> > On 11 April 2011 20:47, Sean Copenhaver <sean.copenhaver@gmail.com>
> wrote:
> >
> > > I think you would have to do a virtual host for both futon and your
> app.
> > >
> > > Something like:
> > >
> > >     futon.domain.com = /_utils
> > >     domain.com = /db/_design/app/_rewrite
> > >
> > > Then in _design/app/_rewrite, something like:
> > >  {
> > >     from: '/'
> > >     to: '_show/show/welcome'
> > >  }
> > >
> > > I have only played around with rewrites a little and have no couchdb
> > right
> > > now to test with, so someone would have to confirm.
> > >
> > > On Mon, Apr 11, 2011 at 2:10 PM, Hendrik Jan van Meerveld
> > > <haaiee@gmail.com>wrote:
> > >
> > > > Thank you Sean,
> > > >
> > > > I am not sure that your sollution will work in my special case.
> > > > It is an existing URL that I want to rewrite.
> > > > The URL 'www.domain.com/' gives the JSON result
> > > > '{"couchdb":"Welcome","version":"1.0.1"}'
> > > > and I want to rewrite it to a HTML welcome page.
> > > > Futon uses 'www.domain.com/' to check the Couchdb version and
> > therefore
> > > > the
> > > > rewrite will break Futon.
> > > > (Or am I wrong? Did anyone rewrite the domain root and still use
> > Futon?)
> > > >
> > > >
> > > > I did solve it in another way. I wrote one rewrite rule (nginx) for
> > port
> > > > 80,
> > > > like this:
> > > >
> > > > server {
> > > >    server_name localhost www.domain.com domain.com;
> > > >    listen [::]:80;
> > > >    ....
> > > >    location =/ {
> > > >      rewrite ^ /db/_design/db/_show/show/home;
> > > >    }
> > > > }
> > > >
> > > > and another rewrite rule for port 81 (without the rewrite for =/):
> > > >
> > > > server {
> > > >    server_name localhost www.domain.com domain.com;
> > > >    listen [::]:81;
> > > >    ....
> > > > }
> > > >
> > > > This way if I go to 'www.domain.com:81/_utils' Futon is still
> working.
> > > >
> > > >
> > > > Hopefully this will help other people to have a welcome page on the
> > > domain
> > > > root and still use Futon.
> > > >
> > > > Kind regards,
> > > > Hendrik Jan
> > > >
> > > >
> > > >
> > > >
> > > > On 10 April 2011 01:02, Sean Copenhaver <sean.copenhaver@gmail.com>
> > > wrote:
> > > >
> > > > > You can actually setup virtual hosts and url rewrites inside
> CouchDB
> > to
> > > > > allow you to pretty much map any URL to a doc or function that you
> > > want.
> > > > It
> > > > > may allow you to go without nginx or with little relying on it:
> > > > >
> > > > >
> > > > >
> > > >
> > >
> >
> http://blog.couchbase.com/whats-new-in-apache-couchdb-0-11-part-one-nice-urls
> > > > >
> > > > >
> > > > > --
> > > > > Sean Copenhaver
> > > > >
> > > > > On Saturday, April 9, 2011 at 6:04 PM, Hendrik Jan van Meerveld
> > wrote:
> > > > > Hi Couch users,
> > > > > >
> > > > > > For my new Couchdb website I am looking to a way to achieve
the
> > > > > following.
> > > > > > I would like my visitors to just type "http://www.mysite.com/"
> and
> > > be
> > > > > > redirected to another page.
> > > > > >
> > > > > > Using Nginx as a reverse proxy works if I use the following
> > rewrite:
> > > > > >
> > > > > > location / {
> > > > > > rewrite ^ /mydatabase/_design/main/_show/blah/home permanent;
> > > > > >  proxy_pass http://localhost:5984;
> > > > > > proxy_redirect off;
> > > > > >  proxy_set_header Host $host;
> > > > > > proxy_set_header X-Real-IP $remote_addr;
> > > > > > proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> > > > > >  }
> > > > > >
> > > > > > The problem with this approach is that Futon starts complaining
> > > because
> > > > > the
> > > > > > welcome page is no valid JSON anymore.
> > > > > >
> > > > > >
> > > > > > Is there a way to redirect "http://www.mysite.com" and still
> keep
> > > > Futon
> > > > > > working.
> > > > > >
> > > > > >
> > > > > > Thanks for any help.
> > > > > > Kind regards,
> > > > > > Hendrik Jan
> > > > > >
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > “The limits of language are the limits of one's world. “ -Ludwig von
> > > Wittgenstein
> > >
> >
>
>
>
> --
> “The limits of language are the limits of one's world. “ -Ludwig von
> Wittgenstein
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message