tornado+nginx multiple subdomain - member profile settings

515 views
Skip to first unread message

Mehmet Kose

unread,
Jun 27, 2012, 5:43:30 AM6/27/12
to python-...@googlegroups.com
application is similar to the following profile pages "site.com / user / username". but I also "username.site.com" I want to run in the style of pages in a structure. What is the nginx configuration for it to be? How do I setup a routing on tornado?

Didip Kerabat

unread,
Jun 27, 2012, 11:13:09 AM6/27/12
to python-...@googlegroups.com
We use something like this:

server {
listen 80;
server_name ~^(?<custom>.+)\.website\.com$;

location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_intercept_errors on;

if ($http_user_agent ~* iphone|android ) {
proxy_pass http://frontends/userland/mobile/$custom;
break;
}

proxy_pass http://frontends/userland/front/$custom;
}
}

/userland/mobile/$custom and /userland/front/$custom are Tornado handlers.

- Didip -

mehmetkose

unread,
Sep 18, 2012, 12:08:52 PM9/18/12
to python-...@googlegroups.com
I'm trying this configuration but, unknown "custom" variable nginx is giving  error.
conflict with other code?


server {
        listen 80;

        # Allow file uploads
        client_max_body_size 50M;

        location static/ {
            root /srv/www/domain.net/static/;
            if ($query_string) {
                expires max;
            }
        }
        location = /favicon.ico {
            rewrite (.*) /static/favicon.ico;
        }
        location = /robots.txt {
            rewrite (.*) /static/robots.txt;
        }

        location / {
            proxy_pass_header Server;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
            proxy_pass http://frontends;
        }
    }

server {
        listen 80;
        server_name ~^(?<custom>.+)\.domain\.net$;

        location / {
            proxy_pass_header Server;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
            proxy_intercept_errors on;

            if ($http_user_agent ~* iphone|android ) {
                proxy_pass http://domain.net/$custom;
                break;
            }

            proxy_pass http://domain.net/$custom;
        }
    }

27 Haziran 2012 Çarşamba 18:13:09 UTC+3 tarihinde Didip Kerabat yazdı:

Didip Kerabat

unread,
Sep 18, 2012, 12:40:17 PM9/18/12
to python-...@googlegroups.com
that means this regex didn't match: ^(?<custom>.+)\.domain\.net$

nginx will create that variable if the regex match.

- Didip - 

Mehmet Kose

unread,
Sep 18, 2012, 12:58:13 PM9/18/12
to python-...@googlegroups.com
yes I know that. variable is used properly, I think, but


command wrong?


Do you use? Is it a required module for variable's?


2012/9/18 Didip Kerabat <did...@gmail.com>

Didip Kerabat

unread,
Sep 18, 2012, 1:06:35 PM9/18/12
to python-...@googlegroups.com
oh, yeah, you have to proxy_pass to your frontend cluster. I was just giving barebone example, perhaps it's too barebone.

- Didip -

Mehmet Kose

unread,
Sep 20, 2012, 3:24:14 PM9/20/12
to python-...@googlegroups.com
Please, look at this Didip, https://gist.github.com/3757510 I always get an error;
[emerg]: unknown "sub" variable
'm trying to solve for days..



2012/9/18 Didip Kerabat <did...@gmail.com>

Didip Kerabat

unread,
Sep 20, 2012, 3:35:09 PM9/20/12
to python-...@googlegroups.com
a couple of things:

* make sure you replace domain.net to your actual domain.

* inside server block with server_name ~^www\.(?<sub>.+)\.domain\.net$:

    location / {
        proxy_pass http://frontends/$sub;
    }

Hope that helps

- Didip -

Didip Kerabat

unread,
Sep 20, 2012, 3:36:22 PM9/20/12
to python-...@googlegroups.com
Oh, and one more thing:

drop the www on www\.(?<sub>.+)\.domain\.net$;

Your expected subdomain is not www.somesubdomain.domain.net, right?

- Didip -

On Sep 20, 2012, at 12:24 PM, Mehmet Kose wrote:

Reply all
Reply to author
Forward
0 new messages