Where is the logics of the Apache precedence?

Discussion in 'Server Operation' started by MaxT, Jun 8, 2017.

  1. MaxT

    MaxT Member HowtoForge Supporter

    Somebody can clarify the logics of Apache 2.2?

    In example: I have 5 websites working with the same ip. Two of them are configured with SSL,
    I have inside /etc/apache2/ports.conf:
    Code:
    NameVirtualHost *:80
    Listen 80
    <IfModule mod_ssl.c>
    Listen 443
    </IfModule>
    and then in /etc/apache2/sites-available I have the Virtualhosts:
    Code:
    <VirtualHost 1.1.1.1:80>
    ServerName website1.com
    ....
    </VirtualHost>
    
    <VirtualHost 1.1.1.1:80>
    ServerName website2.com
    ....
    </VirtualHost>
    
    <VirtualHost 1.1.1.1:80>
    ServerName website3.com
    ....
    </VirtualHost>
    
    <VirtualHost 1.1.1.1:443>
    ServerName website4.com
    ....
    </VirtualHost>
    
    <VirtualHost 1.1.1.1:443>
    ServerName website5.com
    ....
    </VirtualHost>
    
    the problem is: when I load in the browser https://website1.com it loads https://website4.com.
    How can I configure VirtualHosts to avoid this behavior?

    How it works the precedence priority of VirtualHosts? What is the logics?
    How can I know which VirtualHost will be finally loaded in first place?

    Do you know some tutorial explaining this?
     
  2. florian030

    florian030 ISPConfig Developer ISPConfig Developer

    website1 has no ssl enabled so apache uses the first vhost that has ssl enabled. you can create a default-site for ssl that will be used if the site has no ssl. just make sure, that the default-site is always used first (apache sorts the sites alphabetical)
     
    MaxT likes this.
  3. MaxT

    MaxT Member HowtoForge Supporter

    thanks, it worked.
    I have created one in the default site, and now all non-SSL sites are going to the same page when they are requested with https://...
    Code:
    <VirtualHost *:443>
            ServerName myserver.com
            RewriteEngine on
            Redirect / http://www.myserver.com/
            ErrorDocument 404 "Page Not Found"
            DocumentRoot /var/www/myserver.com/web
            SSLEngine on
            SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
            SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
    </VirtualHost>
    
    ...Apache is a bad software. I cannot understand how somebody can design this poor logic to manage the sites. And the information to solve the errors it's a shame.

    thanks again! :)
     
  4. florian030

    florian030 ISPConfig Developer ISPConfig Developer

    It's the same with nginx. What do you expected when you try to load a site that does not exists?
     
    MaxT likes this.
  5. MaxT

    MaxT Member HowtoForge Supporter

    Well, I write a section with the ip and port <VirtualHost 1.1.1.1:80> and inside that section I place "ServerName website1.com",
    Where is the logic in loading https://website1.com and then seeing the load of https://website4.com. The logical thing would be getting an stop, an error or at least a warning because there is no valid 1.1.1.1:443 port configured for "ServerName website1.com."

    If there is a need of seeing Apache jumping freely by all the Servernames at its own will, at least they could include a configuration option to allow that behaviour. Although I wonder where is the need of such behavior when everybody need the association between the ip, port and Servername should be accomplished.

    No option, no warnings, no error, no nothing. I think this is a bad design, just my beginner view. Perhaps there are more things that I don't know.
     
    Last edited: Jun 11, 2017

Share This Page