Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameVirtualHost directive equivalent in Apache 2.4.6?

Tags:

apache

centos

Overview of new features in Apache HTTP Server 2.4 states:

NameVirtualHost directive:
No longer needed and is now deprecated.

Can someone please explain the virtual host equivalent syntax to produce this behaviour in the new version of Apache?


<VirtualHost 127.0.0.3:80>
    DocumentRoot /var/www/html3
    ServerName site3.com
</VirtualHost>

<VirtualHost 127.0.0.3:80>
    DocumentRoot /var/www/html4
    ServerName site4.com
</VirtualHost>

My apologies everyone but I have since destroyed this server and so cannot supply the config file :(

Just FYI I have since seen an example online which placed the server name in the VirtualHost header as seen below which may have been the problem, though I have no way of knowing this until I get an opportunity to test it at some point in the future/

<VirtualHost site3.com:80>
    DocumentRoot /var/www/html3
</VirtualHost>
like image 206
derrend Avatar asked Oct 21 '25 11:10

derrend


2 Answers

Your configuration is correct and automatically behaves as if "NameVirtualHost 127.0.0.3:80" was present. If http://site4.com appears to be the default virtualhost:

  • make sure you're actually testing with "http://site4.com"
  • confirm it's not browser cache
  • try a command-line client
  • make sure the content really differs on disk
like image 79
covener Avatar answered Oct 23 '25 05:10

covener


I agree with @covener. Apache enables SNI based on how many valid vhost blocks it detects for an IP address/port combo. Your question is best answered on apache's official Documentation:

https://httpd.apache.org/docs/2.4/vhosts/details.html

However, for full NameVirtualHost behavior, either pick an internal IP that is routing traffic to your server (use the same IP in all vhost config blocks), or use the wildcard (*):

<VirtualHost *:80>
<VirtualHost *:443>

I, personally, use the wildcard syntax and have roughly 10 different vhost configurations on my own server.

EDIT: I just realized this post is 4 years old.

like image 28
Z McCrocklin Avatar answered Oct 23 '25 05:10

Z McCrocklin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!