I have a droplet in Ubuntu 14.04,what I want to do is create a subdomain and host it in the same droplet.
My main domain : example.com Subdomain created : api.example.com
**What I tried so far: **
Created a “A” record for api.example.com in Networking section
Created a CNAME record for www.api.example.com
Set up the virtual host for api.example.com following this How To Set Up Apache Virtual Hosts on Ubuntu 14.04 LTS
**Below is the step I tried to set up the virtual host **
The droplet is installed Apache2 before,so I didnt install again
Create the directory for my api.example.com by using this command
sudo mkdir -p /var/www/api.example.com/public_html
Create a demo page by using this command nano /var/www/api.example.com/public_html/index.html
and add a simple html code inside it .
I copy the 000-default.conf to my new created conf like this sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/api.example.com.conf
I change the api.example.com.conf to the following:
<VirtualHost *:80>
ServerAdmin myemailaddress@example.com
ServerName api.example.com
ServerAlias www.api.example.com
DocumentRoot /var/www/api.example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo a2ensite api.example.com.conf and restart the apache by sudo service apache2 restartAfter all this step, I test my subdomain,but it doesnt work.It said refused to connect
so what I missing here?? Can somebody help??
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!
Is DNS pointing to your Droplet IP dig api.example.com and dig www.api.example.com ?
Is Apache2 listening on 80 port netstat -tlnpu | grep -i 'apache' ?
Do you have any firewall iptables -nvL with Drop policy and not allowed ports 80 ? Maybe ufw is installed and filtering ports.
Is your config correctly loaded by Apache2 apache2ctl -S ?
I don’t understand - you cannot get IP with dig api.example.com but with host api.example.com you can ?
Please run these commands and paste outputs:
dig example.com NS +short
dig api.example.com +short
dig www.api.example.com +short
It seems to be DNS problem. Please try to override default DNS on your PC, not server by adding 2 lines in “hosts” config file. On Linux/Mac it’s in /etc/hosts. On Windows it’s in %WINDIR%\system32\drivers\etc\hosts. Any changes need to be made with highest privileges by root or Administrator.
Add 2 new lines:
public_ip_of_server www.api.example.com```
And try site in browser.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.