How to setup subdomain on nginx server?

November 11, 2014 61.2k views

Zone file

$TTL 1800 IN SOA 1415711275 10800 3600 604800 1800 1800 IN NS 1800 IN NS 1800 IN NS 1800 IN A 1800 IN A 1800 IN CNAME

I run

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/test

Then edited that file and changed only

    listen 80 default_server;
    #listen [::]:80 default_server ipv6only=on;

    root /var/www/test/mysite/public;
    index index.php index.html index.htm;


and of course restarted nginx server but when I go to it's show my original page. What I doing wrong?

3 Answers

You DNS records seem to be set up correctly, so this does seem to be an issue with your Nginx configuration. Have you linked /etc/nginx/sites-available/test to /etc/nginx/sites-enabled/test

sudo ln -s /etc/nginx/sites-available/test /etc/nginx/sites-enabled/

And of course, remember to restart Nginx so that it pick up the changes:

sudo service nginx restart

For more info, check out this tutorial:

by Justin Ellingwood
Nginx is an incredibly powerful web server and reverse proxy. In this guide, we'll discuss how to set up server blocks on Ubuntu 14.04 in order to server multiple domains from a single server.

Yes I needed to link test to sites-enabled. Thank you.

Nginx requires you to setup subdomain in almost the same way you add a new domain.

You need to do proper 5 steps to add the subdomain or any addon domain, check them out listed here:

Let me know if the issue remains.

Have another answer? Share your knowledge.