... because from time to time I'm a web developer, too
About me
Projects
Contact
Links

Dynamic subdomains via nginx

September 21, 2009 | linux, python, tools
author: Karol Zielinski | comments: 0 | views: 1341
Tags: , , ,

Sometimes we need to handle lots of subdomains (e.g. we want to have URLs like someones_login.ourdomain.com). So, lets configure nginx for this kind of situation.

vim /etc/nginx/sites-available/ourdomain.com

and…


server {
        listen 80;
        server_name ourdomain.com;
        rewrite ^(.*) http://www.ourdomain.com permanent;
}

server {
        listen 80;
        server_name www.ourdomain.com *.ourdomain.com;
        location / {
                proxy_pass http://127.0.0.1:5001;
                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;
                proxy_set_header   X-Forwarded-Ssl  'off';
        }
}

so… we need to add syntax *.ourdomain.com to our server_name.

That’s all. Easy, isn’t it?

Bookmark and Share
Post Dynamic subdomains via nginx to develway Post Dynamic subdomains via nginx to Delicious Post Dynamic subdomains via nginx to Digg Post Dynamic subdomains via nginx to Facebook Post Dynamic subdomains via nginx to Reddit Post Dynamic subdomains via nginx to StumbleUpon

Related news and resources

Write a comment

Karol Zielinski :: Just a tech stuff Hello, I'm Karol Zielinski, internet evangelist, an entrepreneur, project manager and a web developer from Gdynia, Poland. I like creative design, good advertisement, social media and all kind of stuff around the web.

Most popular posts

Much more links

Karol Zielinski    |   contact me
Gdynia, Poland
RSS - Just a tech stuff - python, java blog - web development blog Karol Zielinski on twitter Karol Zielinski on LinkedIn Karol Zielinski on facebook Karol Zielinski on delicious Karol Zielinski on digg Karol Zielinski on flickr Karol Zielinski on stumbleupon Karol Zielinski on technorati