How to set up server/domain name correctly in hosts file with HTTPS
Hosts files for dummies. DNS doesn't give a rip about protocols, it's only there to translate numbers to human readable names. (well mostly true) So revert your hosts file line back to:
192.168.0.2 domain.com www.domain.com
The question is mostly incomplete as you don't explain why a redirect was necessary or if you properly set up your Apache server to accept SSL/TLS connections. I'd vote that the server hasn't been set up to accept port 443 traffic properly and the redirect is sending the traffic to an unresponsive or non-existent HTTPS port.
Since this is a question about a home network, the question will probably be closed as not appropriate to ServerFault.
If your redirect was supposed to change insecure connections to secure connections, the more appropriate way is to test the connection and switch it.
#####################################################
# Control access to php app, secure only
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
I'd recommend dumping the redirect for the nonce and work on getting the server to respond on both HTTP port 80 and HTTPS port 443 with the certificate properly installed. SSL/TLS Strong Encryption: FAQ
Only once you have this working would I recommend trying to direct all the traffic to HTTPS.
Related videos on Youtube
Byakugan
Updated on September 18, 2022Comments
-
Byakugan almost 2 years
I am trying to setup a local network and I am using these kind of types of network.
- Main server which connects to internet with static IP
- Second computer connected to first one locally with address like 192.168.0.2 - when I write this address to address line it is like i wrote localhost in original main server - so it should show my local web browser etc ...
It has domain name this IP and connected router for it ... example www.domain.com so I added to my main server hosts file (linux powered) lines like these:
192.168.0.2 domain.com www.domain.com
It was working ok when I entered my domain name in local computer it showed my site ... But after some time I added HTTPS cerfiticate and added this line to my apatche server:
Redirect permanent / https://www.domain.com/
And now it does not work even when i add something like this to my hosts file:
192.168.0.2 https://www.domain.com
So any idea how do do this thing work? Thank you.
-
Ignacio Vazquez-Abrams about 12 years2 hour penalty for "does not work".
-
MDMarra about 12 yearsYou don't specify a protocol in a hosts file (or DNS A record)
-
Byakugan about 12 years@IgnacioVazquez-Abrams - I do not see any difference between "does not work" and for example "adding https broke my settings" etc it is metter of speech ...
-
Byakugan about 12 years@MDMarra When I do not specify it why is that redirecting causing trouble now?
-
Ignacio Vazquez-Abrams about 12 yearsIf you can't tell the difference between "cause" and "effect" then.... I don't know what to tell you.
-
Byakugan about 12 yearsMaybe help instead of catching me for every word? I am new to this do not know what else could have cause it that is why I write here... I just wrote everything happened and every info I could provide.
-
MDMarra about 12 yearsYou're misunderstanding me. I'm telling you that it is invalid to specify a protocol in an A record or hosts file entry.
-
Byakugan about 12 yearsOK I know this now - It was just what i tried as a logic step for someone who is new to https - what steps I tried etc.
-
Khushboo Tahir about 12 yearsDo you have your hosts file cleaned up so it's not trying to force in an unwanted parameter that will keep the name from resolving to the IP address? So, when you remove the redirect, you can get in on HTTP and HTTPS? Correct?
-
Byakugan about 12 yearsThat is correct :)
-
Khushboo Tahir about 12 yearsOk, if you put the redirect to HTTPS back in, does the site now fail? If so, check your web server error logs, there is probably a line giving you a specific message as to why the server cannot be contacted. You need to enable certain modules for things to work. Your original line,
Redirect permanent / https://www.domain.com/
if letter perfect, requires mod_alias.so to run. My version that checks to see how it was accessed (HTTP or HTTPS and then rewrite if HTTP) requires mod_rewrite.so to be loaded. httpd.apache.org/docs/2.4/mod/mod_so.html#loadmodule -
Byakugan about 12 yearsActually I have it all working meaning that it is working as https with redirect BUT it is not working on localhost ... If I want to use in my local computers domain name instead of localhost that is my problem from the begining :) outside it is working perfectly but on localhost it is working only without https (redirect)
-
Khushboo Tahir about 12 yearsSounds like a name resolution problem. You will need the
192.168.0.2 domain.com www.domain.com
line in the hosts file of every computer on the internal network that needs to contact your web server, including the server itself. -
Byakugan about 12 yearsIt is working when I have it only on the server itself but without permanend redirect to https ... so when i add it to all computers it will work also to another computers in network with https?