Apache virutalhost subdomains point to the same directory

elloo

I have two subdomains of virtual hosts pointing to different directories, however, when I load both subdomains in the browser, I force them to point to the same directory. here is my vhost.conf

<VirtualHost *:80>
        ServerAdmin admin@domain.com
        ServerName subdomain1.domain.com 
        ServerAlias *.domain.com

        #Indexes + Directory Root.
        DirectoryIndex index.php        
        DocumentRoot /subomain1/path/to/directory/trunk

        #Logfiles
        ErrorLog  /subomain1/path/to/directory/trunk/error.log
        CustomLog /subomain1/path/to/directory/trunk//access.log combined
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin admin@domain.com
        ServerName subdomain1.domain.com 
        ServerAlias *.subdomain.com

        DirectoryIndex index.php        
        DocumentRoot /subomain1/path/to/directory/trunk

        SSLEngine On
        SSLCertificateFile /ssl/certs/subdomain1.crt
        SSLCertificateKeyFile /ssl/private/subdomain1.key
        SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
 </VirtualHost>

 <VirtualHost *:80>
        ServerAdmin admin@domain.com
        ServerName subdomain2.domain.com 
        ServerAlias *.domain.com

        #Indexes + Directory Root.
        DirectoryIndex index.php        
        DocumentRoot /subomain2/path/to/directory/trunk

        #Logfiles
        ErrorLog  /subomain2/path/to/directory/trunk/error.log
        CustomLog /subomain2/path/to/directory/trunk//access.log combined
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin admin@domain.com
        ServerName subdomain2.domain.com 
        ServerAlias *.subdomain.com

        DirectoryIndex index.php        
        DocumentRoot /subomain2/path/to/directory/trunk

        SSLEngine On
        SSLCertificateFile /ssl/certs/subdomain2.crt
        SSLCertificateKeyFile /ssl/private/subdomain2.key
        SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
 </VirtualHost>

I tried Google, but none of the answers help.

I am using ubuntu server

thank you very much in advance

+3
source share
2 answers

I don’t know if you allow this, but I had the same problem, and it turned out that I forgot to change the httpd.conf file as follows:

"httpd.conf" uncomment # 461 (approx), "/private/etc/apache2/extra/httpd-vhosts.conf", .

, : http://kevchapman.co.uk/development/setting-up-apache-on-snow-leopard/

+1

, , ServerAlias ​​*.domain.com

ServerAlias ​​, - , -:

ServerAlias ​​*.subdomain.com

subdomain.com subdomain1.domain.com.

http://httpd.apache.org/docs/2.0/vhosts/name-based.html

0
source

Source: https://habr.com/ru/post/1779892/


All Articles