Question

how to connect a droplet to a domain name

I created a droplet and deployed a nextjs project. The IP address displays the content as expected.

I then tried to connect it to a domain name. However, the domain name only displays “welcome to nginx…If you see this page, the nginx web server is successfully installed and working. Further configuration is required.”

The DNS records show that hostname have the value of digitaloccean.com.

Any tip or reference as of what am I’m doing wrong would be highly welcomed.


Submit an answer


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!

Sign In or Sign Up to Answer

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.

alexdo
Site Moderator
Site Moderator badge
April 25, 2023

Hello,

On top of what has already been mentioned, I’ll share this article on How to set up Nginx virtual hosts. The article mentions an old version of Ubuntu but the process is relatively the same for Ubuntu 22.04

https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

Additionally, you can use our NginxConfig tool to generate the desired config file for your site.

https://www.digitalocean.com/community/tools/nginx

Hope that this helps!

KFSys
Site Moderator
Site Moderator badge
April 24, 2023

Hey @leacards,

You need to configure your Nginx to accept your domain name. Most probably, you are using the normal configuration.

If you want to use your domain to proxy requests to your nextJS project with Nginx follow these steps:

SSH into your droplet and create a new Nginx configuration file for your domain:

  1. sudo nano /etc/nginx/sites-available/mydomain.com

Replace mydomain.com with your actual domain name. Add the following configuration, adjusting the server_name and proxy_pass values accordingly:

server {
    listen 80;
    server_name mydomain.com www.mydomain.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

To enable the new configuration, create a symbolic link to it in the sites-enabled directory:

  1. sudo ln -s /etc/nginx/sites-available/mydomain.com /etc/nginx/sites-enabled/
  1. systemctl restart nginx

Again, you’ll need to change the domain to the domain you wish to use.

If you wish to use a standard Nginx configuration, repeat all the steps above but for the config file use this:

server {
    listen 80;
    server_name mydomain.com www.mydomain.com;
    root /var/www/mydomain.com;

    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
}

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel