Virtualhost For Wildcard Subdomain and Static Subdomain

前端 未结 3 1579
感动是毒
感动是毒 2020-11-27 09:40

I have an odd situation where I want to have the URLs app1.example.com, example.com and *.example.com all using a different virtual h

相关标签:
3条回答
  • 2020-11-27 10:25

    This also works for https needed a solution to making project directories this was it. because chrome doesn't like non ssl anymore used free ssl. Notice: My Web Server is Wamp64 on Windows 10 so I wouldn't use this config because of variables unless your using wamp.

    <VirtualHost *:443>
    ServerAdmin test@test.com
    ServerName test.com
    ServerAlias *.test.com
    
    SSLEngine On
    SSLCertificateFile "conf/key/certificatecom.crt"
    SSLCertificateKeyFile "conf/key/privatecom.key"
    
    VirtualDocumentRoot "${INSTALL_DIR}/www/subdomains/%1/"
    
    DocumentRoot "${INSTALL_DIR}/www/subdomains"
    <Directory "${INSTALL_DIR}/www/subdomains/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require all granted
    </Directory>
    

    0 讨论(0)
  • 2020-11-27 10:27

    Wildcards can only be used in the ServerAlias rather than the ServerName. Something which had me stumped.

    For your use case, the following should suffice

    <VirtualHost *:80>
        ServerAlias *.example.com
        VirtualDocumentRoot /var/www/%1/
    </VirtualHost>
    

    There is also more information at https://www.chris-shaw.com/blog/using-wildcards-in-virtual-hosts-on-apache

    0 讨论(0)
  • 2020-11-27 10:43
    <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.

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