0

I am new to apache2 and I am getting some trouble configuring apache2 on Ubuntu Server 12.04 LTS. All the subdomain are pointing to the default one. Here is my objectives:

domain.com -> MAIN SITE (port 80)
sub1.domain.com -> SITE 1 (port 80)
sub2.domain.com -> SITE 2 (port 80)
SSL.domain.com -> SITE 3 (port 443) 

but with my configuration, when i go for example to:

https://sub1.domain.com (port 443)

apache give me the SITE 3 which is not my way, i don't want any return on this subdomain on 443. How to configure well apache2 to have the good domain name pointing at the right SITE on appropriate port and don't answer if i don't want ? Here is a abstract of my site configuration: For main site :

<VirtualHost domain.com:80>
    ServerAdmin [email protected]
    ServerName domain.com
    ServerAlias www.domain.com
    DocumentRoot /var/www/default/public_html

    <Directory />
        Order Deny,Allow
        Deny from all
        Options None
        AllowOverride None
        Options -Indexes -ExecCGI
    </Directory>

    <Directory /var/www/default/public_html>
        Order Allow,Deny
        allow from all
        Options -Indexes -ExecCGI
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined env=!local 
</VirtualHost>

and for each subdomain:

<VirtualHost sub1.domain.com:80>
    ServerAdmin [email protected]
    ServerName sub1.domain.com  
    ServerAlias sub1.domain.com
    DocumentRoot /var/www/sub1/public_html



    <Directory />
        Order Deny,Allow
        Deny from all
        Options None
        AllowOverride None
    </Directory>

    <Directory /var/www/sub1>
                Order Deny,Allow
                Deny from all
                Options None
                AllowOverride None
        </Directory>

    <Directory /var/www/sub1/public_html>
        Order Allow,Deny
        allow from all
        Options -Indexes -ExecCGI
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/sub1_error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/sub1_access.log combined env=!dontlog 
</VirtualHost>

Thanks very in advance for help ! Have a nice day.

1 Answer 1

0

In order to make Apache ignore names that you have not explicitly added, you can add a mod_rewrite rule that checks the ${HTTP_HOST} and sends a Forbidden 403 error if it doesn't match

On the ssl virtual host:

RewriteEngine on
RewriteCond ${HTTP_HOST} !^SSL.domain.com [NC]
RewriteRule /* - [F]

For the non-SSL domains, you can just create a default virtual host that does not specify a ServerName to catch any requests that don't match the domains you want. Just make sure it's listed first (see second section) https://httpd.apache.org/docs/current/vhosts/name-based.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .