logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



What's wrong with my VHosts configuration?

 
Post new topic   Reply to topic    Apache Forum Index -> Apache



View previous topic :: View next topic  
Author Message
Ben321



Joined: 08 Nov 2017
Posts: 1

PostPosted: Thu 09 Nov '17 22:24    Post subject: What's wrong with my VHosts configuration? Reply with quote

This is what I have.
Code:
<VirtualHost *:80>
   ServerName 127.0.0.1
   DocumentRoot "htdocs"
</VirtualHost>

<VirtualHost *:80>
   ServerName localhost
   DocumentRoot "www"
</VirtualHost>


Here's my intent.
Apache will examine the Host field of the HTTP request, and if it contains the literal text "127.0.0.1" then the server will serve files from the "htdocs" folder. However, if the Host field instead contains the literal text "localhost", then the server will serve files from the "www" folder instead. But this is not what's happening.

Here's what's happening.
Apache automatically converts "localhost" to "127.0.0.1". This means that the server ALWAYS servers files from "htdocs". It NEVER serves files from "www".

Now obviously the client (web browser) needs to convert "localhost" to "127.0.0.1" in order to establish the connection (before it even sends the HTTP request), but I also know that whatever you type into the URL bar of the browser is literally what gets sent in the HTTP request to the server. This means that if you type "localhost", that literal text is what gets sent in the Host field of the HTTP request. If you type "127.0.0.1", that literal text is what gets sent in the Host field of the HTTP request. All I want to do, is have Apache act on the literal text in the Host field of the HTTP request header, instead of converting it. Is this possible? If so, how do I do it? If not, consider this to be a feature request for a future version of Apache.
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2123
Location: Sun Diego, USA

PostPosted: Thu 16 Nov '17 0:18    Post subject: Reply with quote

Trying to test this on a fresh build of Apache I ran into the very problem you're having. Almost immediately I realized I forgot to uncomment the Include line in httpd.conf for the vhost file. Once I did that, it worked.

Could this be the problem?
Back to top
Mister Nice



Joined: 07 Nov 2016
Posts: 9
Location: USA

PostPosted: Thu 16 Nov '17 0:28    Post subject: Reply with quote

I'm not sure which version of Apache you have, so the reference to the vhosts file in the comment above may not be relevant, since I think only the more recent versions of Apache are configured as such.
However, I think you may find "NameVirtualHost" useful (just Google it -it's an Apache directive).
Also, maybe you have some specific reason, but why can't you just set up one Virtual Host as 127.0.0.1, and the other one as myfakedomainname.com (or whatever you like); that's easily accomplished by editing your local hosts file (on the machine from which you're intending to browse from).
Back to top


Post new topic   Reply to topic    Apache Forum Index -> Apache
Page 1 of 1