'DigitalOcean DNS Entries from Remote Domain

so I recently set up a droplet on DigitalOcean. For those who don't know, a Droplet is just a virtual server which in my case is running nginx on Ubuntu 20.

Each droplet is given a static ip address and I can connect to my server using that, no problems there.

But typing the IP every time is not what I want. We have a domain where our main website is running, say its example.com. We bought this domain on a different domain provider which has nothing to do with DigitalOcean. I want to direct sub.example.com to the DigitalOcean droplet.

So what I have done is created an A Record for the subdomain which directs to the Droplets IP. I have done this using the control panel from the domain hosting where the main domain is living.

When I look up the domain sub.example.com on a DNS Record Checker I can see that the entry is correctly saved for all locations. Still, when I type it in to my browser I just get a timeout and cant connect at all.

I have certbot installed on that droplet for that subdomain sub.example.com.

Anyone has an idea what I could check? Here is my nginx config for the virtual host:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name sub.example.com;
    root /var/www/sub.example.com/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
server {
    server_name sub.example.com; # managed by Certbot
    root /var/www/sub.example.com/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }


    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/sub.example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/sub.example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = sub.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80 ;
    listen [::]:80 ;
    server_name sub.example.com;
    return 404; # managed by Certbot


}


Solution 1:[1]

I resolved the issue by providing the necessary Domain settings inside DigitalOcean itself, so it needed both the DNS on the Domainserver and on DigitalOcean.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Laisender