Apache2 Dynamic vHost with multiple ServerAlias

后端 未结 2 583
北恋
北恋 2021-01-14 04:39

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


        Se         


        
相关标签:
2条回答
  • 2021-01-14 04:56

    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
    
    0 讨论(0)
  • 2021-01-14 05:04

    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

    0 讨论(0)
提交回复
热议问题