Report this

What is the reason for this report?

How to host my webpage using https or a domain

Posted on November 4, 2025

Hey, I am a beginner in the networking world, and I would like to host my HTML-JS webpage in DigitalOcean. I bought a web-hosting server with SSH access to install the packages needed to run my webpage.

So far, I have installed nginx and added my files to /var/www/html folder, then updated the /etc/nginx/sites-available/default to be something like the following:

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

    root /var/www/html;
    index index.html;

    server_name _;

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

Now it seems that I can access my webpage in http://ip of the DigitalOcean. I would like to do two things: one to access it via https://ip or using a domain name instead. Any ideas on how I can do these two things will be really helpful and welcomed. }



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.

Heya

Great job getting your webpage up and running on nginx.

For HTTPS, you’ll need an SSL certificate. Here’s the thing though - you can’t get a proper SSL certificate for just an IP address. SSL certificates are issued for domain names, not IPs. So you’ll actually need to get a domain name first before you can set up HTTPS properly.

Once you have a domain, the easiest way to get HTTPS working is using Let’s Encrypt (it’s free!) with a tool called Certbot. Here’s how:

Install Certbot:

sudo apt update
sudo apt install certbot python3-certbot-nginx

Get your certificate and auto-configure nginx:

sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

Certbot will automatically modify your nginx config to enable HTTPS and even set up auto-renewal!

2. Using a Domain Name

You’ll need to:

a) Buy a domain from a registrar like Namecheap, Google Domains, or any other provider you prefer.

b) Point your domain to your server by adding an A record in your domain’s DNS settings:

  • Type: A
  • Name: @ (for root domain) or www (for www subdomain)
  • Value: Your DigitalOcean server’s IP address
  • TTL: 3600 (or whatever default they suggest)

c) Update your nginx config to use your domain name:

server_name yourdomain.com www.yourdomain.com;

d) Reload nginx:

sudo nginx -t  # Test the config first
sudo systemctl reload nginx

DNS changes can take a few minutes to a few hours to propagate, so be patient!

Once your domain is working, then run the Certbot command I mentioned above, and you’ll have HTTPS working too.

Heya, @kristosh

If you want proper HTTPS with a domain (recommended): point a domain to your Droplet and use Let’s Encrypt (free, trusted).

In your DNS, create an A record for your domain to your Droplet’s IPv4 (and AAAA to IPv6 if you have it). Example:

example.com -> A -> YOUR_IPV4

www.example.com -> CNAME -> example.com (or another A if you prefer

• Update Nginx to answer for your domain:

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;

    root /var/www/html;
    index index.html;

    location / { try_files $uri $uri/ =404; }
}
sudo nginx -t && sudo systemctl reload nginx

• Open firewall for HTTPS:

sudo ufw allow 'Nginx Full'
sudo ufw delete allow 'Nginx HTTP' 2>/dev/null || true

• Install Certbot and get certs (Ubuntu):

sudo apt update && sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com

Certbot will install the certificate, enable HTTPS, and set up auto-renewal. You’ll have a clean lock icon and no warnings.

Quick tips: keep your site in /var/www/html as you have, run sudo nginx -t before reloads, and use sudo journalctl -u nginx -e if something doesn’t start. If you later add a domain, just repeat the Certbot command with the new -d names.

Hope that this helps!

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.