By kristosh
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!
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!
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:
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.