Question

How to setup subdomain on nginx server?

  • Posted on November 11, 2014
  • almisbAsked by almisb

Zone file

$ORIGIN downjustfor.me.
$TTL 1800
downjustfor.me. IN SOA ns1.digitalocean.com. hostmaster.downjustfor.me. 1415711275 10800 3600 604800 1800
downjustfor.me. 1800 IN NS ns1.digitalocean.com.
downjustfor.me. 1800 IN NS ns2.digitalocean.com.
downjustfor.me. 1800 IN NS ns3.digitalocean.com.
downjustfor.me. 1800 IN A 178.62.153.244
test.downjustfor.me. 1800 IN A 178.62.153.244
www.downjustfor.me. 1800 IN CNAME downjustfor.me.

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;

    server_name test.downjustfor.me;

and of course restarted nginx server but when I go to http://test.downjustfor.me it’s show my original page. What I doing wrong?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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:

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: https://nabtron.com/add-subdomain-nginx/

Let me know if the issue remains.

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