Question

SSL: Domain redirects to IP address for certificate; VirtualHost redirection follows too late

Posted April 13, 2020 188 views
WordPressDNS

Hello,

I have VirtualHost redirections from www.example.com and example.com to https://example.com. Unfortunately, the redirection comes too late.

When people visit www.example.com and example.com, they are immediately redirected to my ip droplet 127.0.0.1 and see the SSL certificate warning. Because Lets Encrypt certifies domains, it says the certificate is only valid from example.com.

When you click “Continue at my own risk.” The VirtualHost redirection works and transfers to my https://example.com.

How can I make the VirtualHost redirection begin before the domains redirect to the IP address?

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.

×
2 answers

Hi there @SomewhereOverThere,

Would you mind sharing the contents of your Virtual Host? I think that the redirect might need to be improved, but I would need to see your current configuration before I could advise you further.

Besides that, you need to make sure that your WordPress site and home URLs are set to your domain name rather than your IP address.

Regards,
Bobby

I solved it. Thanks for the hint to look at localhost. I am writing my response here because I saw like 10 posts on digitaloceans forum, half of the people solved it, but none posted a very clear answer:

SOLUTION:

I looked at apache2.conf (may be httpd.conf for others). I noticed the import for my virtual hosts was /sites-enabled/*.conf and not /sites-available/*.conf. This import line is easily overlooked by a noob. Hey, I chose wordpress one-click install for a reason!

I either misread some of the tutorials or they were written poorly, either way, I had been editing /sites-available/*.conf for hours and restarting apache2.

I opened 000-default.conf and 000-default-le-ssl.conf in /sites-enabled/ and lo and behold saw my localhost IP (e.g., 127.0.0.1). The apache2.conf probably wrote that because I didn’t have a domain when I installed my droplet, so it used my localhost. I modified ServerName and ServerAlias accordingly for both files.

I restarted apache2 and it’s working… for now.

edited by MattIPv4
Submit an Answer