Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

On ec2 I have the parent domain e.g. somedomain.com . I want to setup a subdomain on EC2 which is currently hosting somedomain.com - a subdomain like account.somedomain.com

somedomain.com is running nginx, with a sites-enabled config of:

server {
        listen       80;
        server_name     *.somedomain.com;
        root /home/ubuntu/virtualenv/somedomain/somedomain/homelaunch/;

        access_log /home/ubuntu/virtualenv/somedomain/error/access.log;
        error_log /home/ubuntu/virtualenv/somedomain/error/error.log warn;
        connection_pool_size 2048;

        fastcgi_buffer_size 4K;
        fastcgi_buffers 64 4k;

        location /static {
            alias /home/ubuntu/virtualenv/somedomain/somedomain/homelaunch/static/;
        }

        location / {
            proxy_pass http://127.0.0.1:8001;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_read_timeout 10;
            proxy_connect_timeout 10;
            add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
        }
    }

the somedomain.com is perfectly accessible using EC2, I would like to know how to include a subdomain like account.somedomain.com to the picture and serve different content.

Thank you.

share|improve this question
    
What is the problem you are having? –  Michael Hampton Dec 4 '13 at 22:23

1 Answer 1

up vote 1 down vote accepted

You can just add an extra "server" block with the exact domain name you wish to serve.

As pointed out in the server_name documentation, the exact name takes precedence over wildcard names.

That effectively means that if you add something like this above or below the existing block, you should get the desired result.

server {
    listen       80;
    server_name  account.somedomain.org;
    ...
}
share|improve this answer
    
Do I need to then reinstall everything again on this account.somedomain.org ? e.g. django, etc? –  user700070 Dec 4 '13 at 22:50
    
Additionally, does this require me to restart nginx to take effect? –  user700070 Dec 4 '13 at 22:52
    
Regarding nginx, if you don't change the listen port then no, you can just reload the configuration. service nginx reload will do in most Linux systems. Regarding python and Django, I guess that it will be running behind a different gunicorn/uwsgi process, so you just have to direct the proxy_pass statement to the correct django instance. –  user76776 Dec 4 '13 at 22:54
    
@user700070 Django will operate with the proxy_pass directive, fyi. –  Nathan C Dec 4 '13 at 22:55
    
okay, excellent. Thank you both! –  user700070 Dec 4 '13 at 23:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.