Report this

What is the reason for this report?

DigitalOcean using SSL to serve NgInx Backend on Subodmain

Posted on November 27, 2018

Im currently following a tutorial to install basic Nginx and configure SSL Where I’m kind of lost is that it tells me to add a A Record to my domain configs, which I did, and after running dig +short (domain name) it showed two IPs instead of one, one beeing my DIgitalOcean droplet IP.

I would like to use my www.maindomain.com to serve files using regular Cpanel hosting and api.maindomain.com to point to my droplet Nginx server to serve responses using SSL. Can someone point me out to the right direction because Im getting confused here.



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!

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 there,

It sounds like you’re on the right track. Here are the steps you should follow:

  1. Setup the A Records: You’ll need to set up DNS A records for each subdomain to point to the IP address of the server that will handle it.

    For www.maindomain.com, the A record should point to the IP address of your cPanel hosting. For api.maindomain.com, the A record should point to the IP address of your DigitalOcean droplet.

  2. Configure the Servers: On each server, you’ll need to configure the web server (like Nginx or Apache) to handle requests for its respective subdomain.

    On your cPanel server, you’ll set up a domain or subdomain for www.maindomain.com.

    On your DigitalOcean droplet, you’ll configure Nginx to handle requests for api.maindomain.com. You’ll need to set up a server block in your Nginx configuration for api.maindomain.com and restart Nginx.

  3. Setup SSL: For each subdomain, you’ll need to get an SSL certificate and install it on the respective server. You can use Let’s Encrypt to get a free SSL certificate.

    For the cPanel server, cPanel has built-in support for Let’s Encrypt, which you can use to get and install an SSL certificate for www.maindomain.com.

    For the DigitalOcean droplet, you can use Certbot to get a Let’s Encrypt SSL certificate for api.maindomain.com. You’ll then need to configure Nginx to use this SSL certificate.

As for the dig +short command returning two IP addresses, it’s possible that you have an old DNS record that hasn’t fully propagated out of the system yet. DNS changes can take up to 48 hours to fully propagate. If you’ve made the changes recently, you might just need to wait a bit longer.

If you’ve waited and you’re still seeing two IP addresses, you might want to double-check your DNS configuration to make sure you don’t have an extra record set up for the subdomain.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.