Question about subdomains wildcard

211 views
Skip to first unread message

Didip Kerabat

unread,
Oct 15, 2011, 5:09:07 PM10/15/11
to python-...@googlegroups.com
My problem:

I want to capture any subdomain and pass it along to a handler.

Example: r"(ilovebacon)\.xyz\.com" or r"(snakekebab)\.xyz\.com"

I looked at Application().add_handlers(), but I don't see any way to pass host_pattern to URLSpec instance.

Does this mean:

I need to do proxy_pass on nginx? Like this:

if ( $host ~ ^(.+)\.xyz\.com$ ) {
proxy_pass http://xyz.com/userspace/$1;
}

- Didip -

Peter Bengtsson

unread,
Oct 17, 2011, 9:19:35 AM10/17/11
to python-...@googlegroups.com
You'll achieve this but letting your Nginx server send you its domain name used. You can then in the handler do stuff based on the request.host. E.g.

 def get(self):
      if self.request.host.startswith('ilovebacon.'):
          template = 'bacon.html'
      else:
          template = 'default.html'
      self.render(template)

Reply all
Reply to author
Forward
0 new messages