8

I have a domain http://blabla.com which points to an ip address 103.35.123.4.12. I then have a sub domain http://mew.blabla.com which points to the same ip address. Using nginx how can I differentiate between the two domain names? I currently have the following:

server {
    listen 80;
    server_name blabla.com;

    location ^~ / {

    }
}

server {
    listen 80
    server_name mew.blabla.com;

    location ^~ /mew/ {

    }
}

Currently both blabla.com and mew.blabla.com redirect to the root directory, how can I create a server block for the sub domain?

EDIT: Currently mew.blabla.com is not being recognised as the subdomain, is it a problem with both domains sharing the same IP?

1
  • 1
    No, it is not a problem with both domains sharing the same IP. You don't have any root configuration (which tells nginx from where to serve files) and location doesn't do what I think you think it does (for example, that last one only matches requests for mew.blabla.com/mew/)
    – nickgrim
    Feb 8, 2013 at 12:30

1 Answer 1

10

What you probably want is:

server {
    listen 80;
    server_name blabla.com;
    root /var/www/blabla.com;
    location / {
        try_files $uri $uri/ =404;
    }
}

server {
    listen 80;
    server_name mew.blabla.com;
    root /var/www/mew.blabla.com;
    location / {
        try_files $uri $uri/ =404;
    }
}

So, then content for mew.blabla.com will be served from the path /var/www/mew.blabla.com, while content for blabla.com will be served from the path /var/www/blabla.com.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .