DEV Community

Cover image for Digital Ocean: Setup DNS, Nginx web hosting & G Suite for emails
Thibaut Tiberghien
Thibaut Tiberghien

Posted on

Digital Ocean: Setup DNS, Nginx web hosting & G Suite for emails

Originally posted on Medium on May 8, 2016.

YMMV: The code below is given for the environment and use-case I had at the time of writing, adapt it for your requirements.


  • Web hosting on a Digital Ocean droplet, running Ubuntu 16.04
  • Nginx web server, serving from /var/www/
  • G Suite for email
  • DNS settings on Digital Ocean

1. DNS

Forward DNS management to Digital Ocean

Go to your domain name registrar, search for the DNS settings and set the following external nameservers:

This may take a while to propagate, up to 48h, but usually around an hour or two for me.

Direct web traffic for your domain to your droplet

Login to, go to Networking, then Domains. Add a domain and link it to the relevant droplet. After that, click “view” for your newly added domain and add a CNAME record for www pointing towards your main A record, in my case, with the trailing dot. You should be good to go.

Direct email traffic for your domain to G Suite

Login to, go to Networking, then Domains. Click “view” for your domain, then “MX”, then hit the “Add Gmail MX records”. You’re done!

2. Web Hosting

Setup Nginx to host your website

Install Nginx:

sudo apt-get update
sudo apt-get install -y nginx
sudo update-rc.d nginx defaults

It should be running after install, you can check with

sudo service nginx status

Add the site’s config file (/etc/nginx/sites-available/

server {
       listen       80;
       listen       [::]:80;
       return       301 $scheme://$request_uri;

server {
       listen 80 default;
       listen [::]:80 default;

       root /var/www/;

       index index.min.html index.html;


       gzip_static on;
       gzip_proxied no-cache no-store private expired auth;
       gzip_http_version 1.0;

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

Note: you can only have one default server, so in case you are co-hosting several websites, remember to choose the one you want.

Enable your site:

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Disable the default Nginx site:

sudo rm /etc/nginx/sites-enabled/default

You can play around with more settings in your site’s config file or in Nginx config (/etc/nginx/nginx.conf) to affect all of your websites.

You can now copy your website’s files to /var/www/ and it should work once the DNS is propagated. You can already try to hit the site using the IP of your droplet.

Top comments (0)