简体   繁体   中英

Apache2 Dynamic vHost with multiple ServerAlias

I am trying to set up a dynamic vHost, but have run into some trouble. It will not allow me to set multiple ServerAlias.

<VirtualHost *:80>
        ServerAlias *.com
        ServerAdmin michael.ian.curry@gmail.com
        VirtualDocumentRoot /var/www/%1/production/html
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
        LogLevel warn
</VirtualHost>

The above vHost only works for ' .com' i need it to work for 'www. .com' and '*.com' I assumed that setting the ServerAlias to would fix it, but it is not working.

ServerAlias *.com www.*.com

If you have any insight, please respond

--MichaelCurry

==EDIT 1==

Example redcrusher.com and www.redcrusher.com

==EDIT 2==

The code below does not work either

ServerAlias www.*.com *.com

Figured it out!

'www.*.com' must execute before '*.com' This is because ServerAlias is setting a dynamic domain and must exist before a "smaller" alias exists.

Example: 'www.*.com', 'dev.*.com', 'asdf.*.com' THEN '*.com'

vHost File [production.conf]:

<VirtualHost *:80>
    ServerAlias www.*.com
    VirtualDocumentRoot /var/www/%2/production/html
    ServerAdmin michael.ian.curry@gmail.com
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    LogLevel warn
</VirtualHost>

<VirtualHost *:80>
    ServerAlias *.com
    VirtualDocumentRoot /var/www/%1/production/html
    ServerAdmin michael.ian.curry@gmail.com
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    LogLevel warn
</VirtualHost>

I hope this helps anyone else that is having this problem!

--MichaelCurry

you must use like this

ServerAlias www.domain.com domain.com
ServerAlias *.domain.com

if You want use That Way You Must Follow Order

ServerAlias www.*.com *.com 

the problem is of

VirtualDocumentRoot /var/www/%1/production/html

you Use a Dynamic VirtualDocumentRoot that mean

for redcrusher.com VirtualDocumentRoot is

/var/www/redcrusher/production/html

and for www.redcrusher.com VirtualDocumentRoot is

/var/www/www.redcrusher/production/html

I think with split ServerAlias in Three part it solve

ServerAlias www.*.com
VirtualDocumentRoot /var/www/%1/production/html/
ServerAlias *.*.com
VirtualDocumentRoot /var/www/%2/production/html/%1 
ServerAlias *.com 
VirtualDocumentRoot /var/www/%1/production/html

i think should Work

VirtualDocumentRoot :

redcrusher.com

/var/www/redcrusher/production/html

www.redcrusher.com

/var/www/redcrusher/production/html/

sub.redcrusher.com

/var/www/redcrusher/production/html/sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM