Django Getting apache default page using ssl certificate

I have my Django project with an SSL certificate from Let’s Encrypt, deployed on an Ubuntu 22.04 (LTS) x64 virtual machine from Digital Ocean.

When I navigate to the page using my domain, it redirects me to my page correctly, but when I use the IP address, it redirects me to the apache default page.

I have a PTR record active on the Digital Ocean site:

IPv4: ip address ....... 
AddressPTR Record: [](

The ip address added to the ALLOWED_HOSTS var on my

ALLOWED_HOSTS = ['', 'my ip address']

What I have in /etc/apache2/sites-available/my_project.conf:

<VirtualHost *:80>


ServerAlias [](

ServerAdmin webmaster@localhost

DocumentRoot /var/www/html

RewriteEngine on

RewriteCond %{SERVER_NAME} [OR]

RewriteCond %{SERVER_NAME}

RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

The traffic allowed in my server:

Status: active


22/tcp ALLOW Anywhere
80/tcp ALLOW Anywhere
Apache Full ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
Apache Full (v6) ALLOW Anywhere (v6)

Before getting the SSL certificate, it worked using the ip address as well but, when I set the certificate, it just returns the apache default page. I set the certificate following this five step tutorial:

I hope that’s the right information in order to get an answer, I’m learning Django and Web Development in general, I hope this question makes sense.

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.

Bobby Iliev
Site Moderator
Site Moderator badge
February 22, 2023

Hi there,

What you could do here is to update your default Apache virtual host which is the virtual host that servers the traffic for your IP and add the rewrite rule in there as well, eg:

RewriteEngine on

RewriteCond %{SERVER_NAME} [OR]

RewriteCond %{SERVER_NAME}

RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

Once you make the change, do a quick config test with sudo apachectl -t and if you get Syntax Ok restart Apache.

That way when someone visits your IP, they will be redirected to your domain which would serve the correct content ovar HTTPS.

Let me know how it goes!



Try DigitalOcean for free

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

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

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

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
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
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.