I’m setting up a Virtual Hosts file on my CentOS 7 box and I’m having trouble getting my domain to resolve correctly.
Here’s what my current /etc/httpd/conf.d/vhost.conf
file looks like
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName www.domain.com
ServerAlias domain.com
DocumentRoot /var/www/html/domain.com/public_html/
ErrorLog /var/log/httpd/error.log
CustomLog /var/log/httpd/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.domain.com [OR]
RewriteCond %{SERVER_NAME} =domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
It seems the the correct redirects are happening. For exmaple:
domain.com redirects to https: //www.domain.com
www works fine
BUT
https: //domain.com doesn’t work
http ://domain.com doesn’t work
In fact, if I remove the redirects I have set, domain.com ins’t working at all, so it looks like the ServerAlias is broken?
I’m wondering if I need another redirect or is there some other step I’m missing?
Also, don’t mind the spaces between http and the domain name. StackOverflow made me format it that way.
2
Answers
I solved the issue. I had my local hosts file configured to point to an old out of date IP address……
domain.com *bad ip address*
I'm so embarrassed. I must have set that up months ago and forgot.
As presented, no request to anything
https
will ever work. Normal, you only have aVirtualHost
on port 80. You do have aListen
directive for that port right?For your redirections. It says: if you ask for
http://www.example.com
orhttp://example.com
, redirect tohttps://<WHAT THE USER ASKED FOR>
. In essence you are forcing your users to use https all the time, no problem there. But you do not have aVirtualHost
on port 443, hence no response.So:
DocumentRoot
in *:80 VH since it only redirects and does not respond content to client.Have fun!