Wildcard Virtual Hosts Ubuntu

Virtualhost For Wildcard Subdomain and Static Subdomain

<VirtualHost *:80>
DocumentRoot /var/www/app1
ServerName app1.example.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /var/www/example
ServerName example.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /var/www/wildcard
ServerName other.example.com
ServerAlias *.example.com
</VirtualHost>

Should work. The first entry will become the default if you don't get an explicit match. So if you had app.otherexample.com point to it, it would be caught be app1.example.com.

Virtualhost wildcard subdomain of wildcard subdomain in apache2.4

The above code has the right syntax but I just put it to the wrong placement order. So the correct answer is to put the second one to the top above the first one.

Below full config example :

<VirtualHost *:80>
ServerAlias *.*.domain
ErrorLog /tmp/error.log
CustomLog /tmp/access.log combined
VirtualDocumentRoot /var/www/%2/public
<Directory "/var/www">
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerAlias *.domain
ErrorLog /tmp/error.log
CustomLog /tmp/access.log combined
VirtualDocumentRoot /var/www/%1/public
<Directory "/var/www">
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Apache is skipping/ignore the same subdomain/domain config by ascending order from the top. sub.sub.domain is also a part of *.domain , so if I want to configure it I must put the config in the top or if use different file config use lower number name.

Multiple ServerAlias or ServerName or NameVirtualHostlines will yield a "NameVirtualHost *:80 has no VirtualHosts" warning. Apache will ignore the second directive and use the first defined NameVirtualHost line, though. This seems to happen when one is using multiple virtual host configuration files and doesn't understand that you only need to define a particular NameVirtualHost line once

reference

Simple solution but I workaround for some hours and I hope it helps other people like me.

Wildcard Virtual Hosts Ubuntu

for Ubuntu it goes as simple as

sudo apt-get install dnsmasq
sudo echo "address=/weblocal/127.0.0.1" >> /etc/dnsmasq.d/weblocal
sudo /etc/init.d/dnsmasq restart

VirtualHost with wildcard VirtualDocumentRoot

I use them :) You forgot about switching off canonical names - unfortunately I don't know why there must be ServerAlias in my configuration - it just won't work without it - code below is tested and working

<Directory "C:/LocalServer/*/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require local
</Directory>

<VirtualHost *:80>
# Apache will form URLs using the hostname supplied by the client
UseCanonicalName Off

# available aliases to use
ServerAlias *.lab *.lab2

# where to put them
VirtualDocumentRoot "C:/LocalServer/%2/%1/public/"
</VirtualHost>

Default virtualhost overriding wildcard subdomain virtual host

I have fixed it by placing this snippet above default and removing ServerName. The issue was that I had ServerName in the root www., but I'm not using www.

Creating Wildcard Sub Domain Using Apache VirtualHost

Wildcard sub-domains are definitely possible using Apache virtual hosts.

I had basically the same requirements and managed to get it working with Apache's mod_vhost_alias.so module. Try this in your http-vhosts.conf file:

DocumentRoot "/home/admin1/public_html/userweb/" 
<Directory "/home/admin1/public_html/userweb/">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>

<VirtualHost *:80>
DocumentRoot /home/admin1/public_html/
ServerName www.example.com
</VirtualHost>

<VirtualHost *:80>
VirtualDocumentRoot /home/admin1/public_html/userweb/%1.example.com/
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /home/admin1/public_html/
ServerName example.com
</VirtualHost>

Note that I haven't tested this, but it's pretty close to the solution that worked for me.

Full details of my solution are here:
http://www.calcatraz.com/blog/wildcard-subdomains-in-apache-1422

apache 2.4 serverAlias with * wildcard overwrittes specificed vhost

Turns out the order in which it is setup matters.
Apache apparently looks for the matching host it can find.

Since the first config was in 000-default.conf and the second one was in the 020-dev.conf the dev-subdomain matched the first vhost and used that.

I changed default to 999-default.conf which means now dev will first be matched with the proper vhost but other undefined subdomains will still be matched with the default vhost.

Virtualhost For Wildcard and Static Subdomain

My own research gave me the only workaround so far. I've ended up using another port for app1.example.com.

<VirtualHost *:8080>
DocumentRoot /var/www/app1
ServerName app1.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/example
ServerName example.com
ServerAlias *.example.com
</VirtualHost>


Related Topics



Leave a reply



Submit