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: httpd.conf default site gets overridden by the first vhost
Author
Zane_TLI



Joined: 28 May 2017
Posts: 11
Location: Ferrara, Italy

PostPosted: Sun 28 May '17 23:39    Post subject: httpd.conf default site gets overridden by the first vhost Reply with quote

Hi guys,
I'm detecting a behaviour I'm not expecting and I'd like some clarification with Apache 2.4.25 on Windows 10 x64 (httpd-2.4.25-win64-VC14.zip from ApacheLounge).

I've defined a "main" server config in httpd.conf:


Code:

...
ServerName www.my-default-site.com:80
DocumentRoot "C:\Users\info\Web\default"
<Directory "C:\Users\info\Web\default">
...


This works as expected on its own: every request gets a response from this site, whatever the domain is.

But then I add this to httpd.conf:

Code:
Include conf/vhosts/*.conf


Said folders has one file: miaazienda.conf

Code:

<VirtualHost *:80>
   ServerName miaazienda.com
   DocumentRoot "C:\Users\info\Web\miaazienda"
   <Directory "C:\Users\info\Web\miaazienda">
      AllowOverride None
      Options FollowSymLinks
      Require all granted
   </Directory>
</VirtualHost>


Expected behaviour

The expected behaviour is this:

* http://miaazienda.com gets handled by the virtualhost
* http://every-other-domain.com gets handled by the default config in httpd.conf

This is the expected behaviour because the comment in httpd.conf clearly states so:

Quote:

# 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition.



Actual behaviour

I **always** get a response from the virtualhost, both for the miaazienda.com domain and for every other undefined virtualhost.

If I create a second virtualhost file (miosito.conf) to handle http://miosito.com => http://miosito.com gets handled by the new vhost, but every other undefined virtualhost still get handled by miaazienda.com (the first vhost).

If I create a last virtualhost as aaaa.conf => boom, new "catch-all" for the undefined domain!


So.... either I'm missing something or the comment in httpd.conf is wrong and the httpd.conf config always gets overridden by the first (in alphabetic order) vhost file.

I already found a working solution (Include conf/vhosts/default.conf before Include conf/vhosts/*.conf in httpd.conf) but still, I'd like to understand what's going on here.

Thanks!
Back to top
glsmith
Moderator


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

PostPosted: Mon 29 May '17 0:48    Post subject: Reply with quote

1st vhost
<VirtualHost _default_:80>
DocumentRoot "C:\Users\info\Web\default"
</VirtualHost>

That's all you need, this will pick up everything not specified in any vhost section including http://your-ip-address. Your miaazienda.com vhost however will be work as should. When you go to main site www.my-default-site.com you will see what you expect.

Leave the stuff in httpd.conf, it grants access with the global scope <Directory>.


Last edited by glsmith on Mon 29 May '17 0:59; edited 1 time in total
Back to top
Zane_TLI



Joined: 28 May 2017
Posts: 11
Location: Ferrara, Italy

PostPosted: Mon 29 May '17 0:58    Post subject: Reply with quote

@glsmith thanks man, it works like a charm!

Still: this is on-vhost configuration: the "main" config (DocumentRoot+Directory) in httpd.conf continues to be ignored. Other than wrapping **it** into a <VirtualHost _default_:80> block, is there any other way to have **it** the default?
Back to top
glsmith
Moderator


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

PostPosted: Mon 29 May '17 1:01    Post subject: Reply with quote

It is the default, like I said, go to http://your-ip-address and you will get the "main/default" site. It's the default.

Edit: Yes, once you set a single vhost the global us ignored. How it works and has worked in the 20 years I've been using Apache.

I have my default host set to just a page that says "there is no site at this address"


Last edited by glsmith on Mon 29 May '17 1:07; edited 1 time in total
Back to top
Zane_TLI



Joined: 28 May 2017
Posts: 11
Location: Ferrara, Italy

PostPosted: Mon 29 May '17 1:12    Post subject: Reply with quote

glsmith wrote:
Edit: Yes, once you set a single vhost the global us ignored.


That's the anomaly I'm reporting! as I stated, the comment above the main config in httpd.conf reads:

Quote:
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition.


That's simply not true because, as you confirmed, it's the <VirtualHost _default_:80> one who responds.
Back to top
glsmith
Moderator


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

PostPosted: Mon 29 May '17 1:29    Post subject: Reply with quote

It is a documented caveat when using name based virtual hosts as "Main host goes away." I point you to the 2.2 docs because they are worded best and even this is not great, but better than they have it now in the 2.4 docs.

http://httpd.apache.org/docs/2.2/vhosts/name-based.html
http://httpd.apache.org/docs/2.4/vhosts/name-based.html
Back to top
Zane_TLI



Joined: 28 May 2017
Posts: 11
Location: Ferrara, Italy

PostPosted: Sat 03 Jun '17 9:53    Post subject: Reply with quote

Thanks man, that's the reference I was looking for!

I linked this topic in my guide "Come installare Apache su Windows 10 e trasformare il PC in un server web: la Guida Definitiva" Very Happy
Back to top


Reply to topic   Topic: httpd.conf default site gets overridden by the first vhost View previous topic :: View next topic
Post new topic   Forum Index -> Apache