logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


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

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Newbie question about hosts file and VirtualHost
Author
stardustvega



Joined: 28 Feb 2023
Posts: 8

PostPosted: Fri 31 May '24 13:19    Post subject: Newbie question about hosts file and VirtualHost Reply with quote

I'm just getting started with learning Apache by playing around using it as a local development environment on my Windows 11 machine and trying out different directives.

I've been googling around but I haven't gotten a clear answer on this.

If you want to use a URL for your local site (e.g. mysite.test instead of 127.0.0.1), I see that you can do that using VirtualHost and also editing the hosts file. I've got it working using that method.

My question is, do you HAVE to edit the hosts file to get this to work in Windows, or is there a different way to do it using the configuration settings in Apache, or maybe a module?

I see in the notes on the virtual hosts documentation:
Quote:
Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You must have the names in DNS, resolving to your IP address, or nobody else will be able to see your web site. You can put entries in your hosts file for local testing, but that will work only from the machine with those hosts entries.

It's just not clear to me if this is saying 'one way to handle this in your local environment is to use the hosts file' or if it's saying 'the only way to handle this in your local environment is to use the hosts file'.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7316
Location: Germany, Next to Hamburg

PostPosted: Fri 31 May '24 14:59    Post subject: Reply with quote

You have to edit the HOSTS file if you have no external DNS server. It is not Apache, but the Windows OS that resolves the DNS name.

I use vhosts like test1.local.apachehaus.de since all *.local.apachehaus.de point to 127.0.0.1 Wink
Back to top
stardustvega



Joined: 28 Feb 2023
Posts: 8

PostPosted: Sat 01 Jun '24 0:21    Post subject: Reply with quote

Quote:
It is not Apache, but the Windows OS that resolves the DNS name.

Ah, perfect, thank you. I could not seem to find the right combination of search terms to get to that answer.
Quote:
I use vhosts like test1.local.apachehaus.de since all *.local.apachehaus.de point to 127.0.0.1

Oh, I didn't think of that, thank you! I had gotten it working by using two entries in my hosts file; I wasn't thinking about using wildcards.
Back to top
stardustvega



Joined: 28 Feb 2023
Posts: 8

PostPosted: Tue 04 Jun '24 14:05    Post subject: Reply with quote

Quote:
I use vhosts like test1.local.apachehaus.de since all *.local.apachehaus.de point to 127.0.0.1


Hrm. Are you taking about being able to use a wildcard in the hosts file, or are you referring to having your own convention where you just know you're going to name all of your hosts by that style?

I can't get wildcards to work in my hosts file and doing some googling around suggests that it doesn't work (at least on Windows).[/quote]
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7316
Location: Germany, Next to Hamburg

PostPosted: Wed 05 Jun '24 12:57    Post subject: Reply with quote

In the hosts file you can't have a wild card.

I have DNS Server and an A record .local.apachehaus.de point to 127.0.0.1
Back to top


Reply to topic   Topic: Newbie question about hosts file and VirtualHost View previous topic :: View next topic
Post new topic   Forum Index -> Apache