Reputation: 7587
I downloaded Apache binary from http://www.apachelounge.com/ After installing, in the httpd.conf
file on line 220, I changed #ServerName www.example.com:80
to ServerName www.example.com:80
. Now everything works fine. The server users the domain name localhost
. Also localhost:80
automatically redirects to localhost
.
Since
ServerName
iswww.example.com:80
then why does the server work onlocalhost
instead ofwww.example.com:80
?If I change every instance of
www.example.com:80
tomylocalserver:80
then why doesn't the apache server work onmylocalserver:80
?
Upvotes: 1
Views: 13420
Reputation: 1128
Your question doesn't give a whole lot of information, but I'll try to answer it anyway.
Also localhost:80 automatically redirects to localhost.
That's probably not a redirect, but your browser removing the :80
part as it's the default port on the web.
Since ServerName is www.example.com:80 then why does the server work on localhost instead of www.example.com:80?
Probably because both localhost
and www.example.com
refer to the web server, and the web server responds to both of them. localhost
is commonly configured to be 127.0.0.1
and thus will refer to your local set-up.
If I change every instance of www.example.com:80 to mylocalserver:80 then why doesn't the apache server work on mylocalserver:80?
mylocalserver
might not be referring to anything. Try editing your hosts
file (/etc/hosts
on *nix, %SYSTEM%\Drivers\etc\hosts
) to include mylocalserver
to refer it to 127.0.0.1
just like localhost
.
The problems you're having seem to stem from a misunderstanding about the domain names. Domain names translate into IP addresses. www.example.com
translates to some IP address on the internet, but localhost
translates into 127.0.0.1
usually, like defined in the hosts
file. You may also just use the IP address in the ServerName
variable, such as 127.0.0.1
.
Upvotes: 1
Reputation: 2900
DNS as in name resolution happens before you reach Apache HTTPD Server. When you put a name in your browser or anywhere, that you reach your server or not depends only on that resolution and if resolves the ip of the server you have configured, so it has nothing do be with how httpd is configured that you reach it with one name, and you don't with another.
As for httpd, it works on any name you may want because HTTPD does not know about your DNS setup. It listens on a IP address and if a request reaches the server (through the ip:port it is binded to) then and only then it will check the "Host" http header inside the request to decide to which virtualhost (if more than one and it has been configured properly) to deliver the request.
So you can use any name you like, what matter is how you resolve it and on which ip:port combination you end up.
Upvotes: 1