A
A
admin4eg2012-05-16 05:06:34
Django
admin4eg, 2012-05-16 05:06:34

Nginx rewrite subdomains + django?

The trouble is, there is a site structure something like this
site.ru/company1/menu
site.ru/company2/menu
site.ru/company3/menu
This is all implemented with a bang on Django
. I want the user to see it as
company1.site.ru/menu
company2 .site.ru/menu
company3.site.ru/menu
But the trouble is how to make it work on subdomains. use batteries from django for example django-hosts
or rewrites on nginx can solve this case?
about django-hosts, it turns out that I can easily put an application on a subdomain, and my applications will be in all subdomains, for example, the news application will be for all company*
how to be?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
VBart, 2012-05-16
@admin4eg

The nginx config will look something like this:

    server {
        server_name ~^(?<company>.+)\.site\.ru$;

        location / {
            try_files /path/to/static/media @django;
        }

        location @django {
            fastcgi_pass unix:/tmp/site.django.socket;

            fastcgi_param PATH_INFO /$company$uri;
            fastcgi_param REQUEST_METHOD $request_method;
            fastcgi_param QUERY_STRING $query_string;
            fastcgi_param CONTENT_TYPE $content_type;
            fastcgi_param CONTENT_LENGTH $content_length;
            fastcgi_param REMOTE_ADDR $remote_addr;
        }
    }

But you should keep in mind that django needs to know how to generate the correct links. Those. instead /company1/menu/item, it will have to create a link /menu/item.

M
mikevmk, 2012-05-16
@mikevmk

server_name ~(.*).site.ru;
set $company $1;
on my own ;)

E
ertaquo, 2012-05-16
@ertaquo

Have a look here: http://stackoverflow.com/questions/2785538/nginx-subdomain-rewrite

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question