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: [www.mydomain.com](http://www.mydomain.com/).
The ip address added to the ALLOWED_HOSTS var on my settings.py
:
ALLOWED_HOSTS = ['www.mydomain.com', 'my ip address']
What I have in /etc/apache2/sites-available/my_project.conf
:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias [www.mydomain.com](http://www.mydomain.com/)
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mydomain.com [OR]
RewriteCond %{SERVER_NAME} =mydomain.com
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:https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-22-04
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.
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.
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.
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:
Once you make the change, do a quick config test with
sudo apachectl -t
and if you getSyntax 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!
Best,
Bobby