Question

How to create subdomain with nginx server in the same droplet

I am new at digital ocean. I have created a droplet and a domain. It will be great help if i get dns configuration for subdomain and step by step procedure to create a subdomain in same droplet.
TIA

Subscribe
Share

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

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.

Hi

<^>Now you need to enable the configuration, make a symlink to the enabled sites:

ln -s /etc/sites-available/sub.test.com /etc/sites-enabled/sub.test.com<^>

I think it’s

ln -s /etc/nginx/sites-available/sub.test.com /etc/nginx/sites-enabled/sub.test.com

Hi

<^>Now you need to enable the configuration, make a symlink to the enabled sites:

ln -s /etc/sites-available/sub.test.com /etc/sites-enabled/sub.test.com<^>

I think it’s

ln -s /etc/nginx/sites-available/sub.test.com /etc/nginx/sites-enabled/sub.test.com

Hi

<^>Now you need to enable the configuration, make a symlink to the enabled sites:

ln -s /etc/sites-available/sub.test.com /etc/sites-enabled/sub.test.com<^>

I think it’s

ln -s /etc/nginx/sites-available/sub.test.com /etc/nginx/sites-enabled/sub.test.com

Hello,

You can easily make a website on any (sub)domain you would like to use.

First of all you would need the website files. You can put them somewhere inside /var/www. In this “tutorial” we will use /var/www/sub.test.com You also need to have your DNS records setup properly, so your subdomain redirects to your droplet. For example:

sub.test.com. 1800 IN A 123.345.234.4

Now you can configure nginx to serve a specific website on a specific domain. Make a new configuration in nginx (rename test.com to anything that reminds you of the config):

sudo nano /etc/nginx/sites-available/sub.test.com

Inside the configuration place and edit the following:

server {
        listen 80;

        root /var/www/sub.test.com;
        index index.html index.htm index.nginx-debian.html;

        server_name sub.test.com www.sub.test.com;

        location / {
                try_files $uri $uri/ =404;
        }
}

<^>Inside this configuration modify the following to your specific setup:

  • root (your website file directory)
  • server_name (your website domain)<^>

Now you need to enable the configuration, make a symlink to the enabled sites:

ln -s /etc/sites-available/sub.test.com /etc/sites-enabled/sub.test.com

Last thing to do is restart nginx:

service nginx restart

You should now be able to check the website on your subdomain. Hope it will work, if you have any questions just ask!

Hello,

You can easily make a website on any (sub)domain you would like to use.

First of all you would need the website files. You can put them somewhere inside /var/www. In this “tutorial” we will use /var/www/sub.test.com You also need to have your DNS records setup properly, so your subdomain redirects to your droplet. For example:

sub.test.com. 1800 IN A 123.345.234.4

Now you can configure nginx to serve a specific website on a specific domain. Make a new configuration in nginx (rename test.com to anything that reminds you of the config):

sudo nano /etc/nginx/sites-available/sub.test.com

Inside the configuration place and edit the following:

server {
        listen 80;

        root /var/www/sub.test.com;
        index index.html index.htm index.nginx-debian.html;

        server_name sub.test.com www.sub.test.com;

        location / {
                try_files $uri $uri/ =404;
        }
}

<^>Inside this configuration modify the following to your specific setup:

  • root (your website file directory)
  • server_name (your website domain)<^>

Now you need to enable the configuration, make a symlink to the enabled sites:

ln -s /etc/sites-available/sub.test.com /etc/sites-enabled/sub.test.com

Last thing to do is restart nginx:

service nginx restart

You should now be able to check the website on your subdomain. Hope it will work, if you have any questions just ask!

Getting 502

There’s a mistake in this article… you’ve left out the /nginx directory. So:

ln -s /etc/sites-available/sub.test.com /etc/sites-enabled/sub.test.com

…should be…

ln -s /etc/nginx/sites-available/sub.test.com /etc/nginx/sites-enabled/sub.test.com

change this comand ln -s /etc/nginx /sites-available/sub.test.com /etc/sites-enabled/sub.test.com to ln -s /etc/nginx /sites-available/sub.test.com /etc/sites-enabled/sub.test.com :)

follow this tutorial How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 14.04 LTS

after that just add CNAME for that subdomain in DNS settings if you need details on DNS settings, check this tutorial

How To Set Up and Test DNS Subdomains with DigitalOcean’s DNS Panel