i have a problem setting up subdomains with nginx

Posted November 3, 2014 3.2k views

hey there i am running the one click installation of django on ubuntu 12.04, i also have installed a ghost blog on the same vps, but when configuring the available-sites on nginx i have come to a problem.

my regular domain is this one points to my django project

i have the “django” file that come for default with the one click installation in etc/nginx/sites-enabled, to this one i have added another “server” instance to point to the ghost blog when the server name is

but it is not working.

after tweaking a little i discover that it stops working when i use subdomains like *

when y configured it with another full domain. it works like a charm.

but if i edited the configuration files of nginx with a subdomain in the server_name attributte it fails.

here is how my current sites-available looks like:

upstream app_server {
    server fail_timeout=0;

server {
    listen 80;

    root /usr/share/nginx/html;
    index index.html index.htm;

    client_max_body_size 4G;
   #  server_name _;

    keepalive_timeout 5;

    # Your Django project's media files - amend as required
    location /media  {
        alias /home/django/django_project/django_project/media;

    # your Django project's static files - amend as required
    location /static {
        alias /home/django/django_project/django_project/static; 

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;

server {
    listen 80;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_redirect off;


if i change the server name from to ngninx fails to restart it service. (figure that out after a hole day trying)

so ther yo have it. at this point i am pretty clueless thank you for any help you can get me.

1 comment
  • Hi! Are there any errors in nginx’s error log?

    sudo tail /var/log/nginx/error.log

    You might need to increase server_names_hash_bucket_size in /etc/nginx/nginx.conf.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

yeah that was the solution, go to /etc/nginx/nginx.conf unncoment the line with servernameshashbucketsize and set it up with a higher number.