Dynamic subdomains via nginx
September 21, 2009 | linux, python, toolsauthor: Karol Zielinski | comments: 0 | views: 527
Tags: domain, nginx, python, subdomain
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?
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.