简体   繁体   中英

apache2 vhost loads wrong project

TL;DR: I have two VHOST's but the second one (phpmyadmin.conf) does point to the directory of the first one.


I have four VHOST's:

  • phpmyadmin.conf
  • phpmyadmin_ssl.conf
  • test_api_konfigurator.conf
  • test_api_konfigurator_ssl.conf

/etc/hosts:

127.0.0.1 localhost
127.0.0.1 test.api.konfigurator.company.de
127.0.0.1 phpmyadmin.aws1.company.de

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

The two subdomains are just CNAME records from my DNS server to my project server:

phpmyadmin.aws1.company.de.         300 CNAME   ec2-xxx-xxx-xxx-xxx.eu-central-1.compute.amazonaws.com
test.api.konfigurator.company.de.   300 CNAME   ec2-xxx-xxx-xxx-xxx.eu-central-1.compute.amazonaws.com

Problem:

Both project's have a "index.php" with this code exit("hello from phpmyadmin.aws1.company.de"); and respectively exit("hello from test.api.konfigurator.company.de"); in the first line.

If I call https://test.api.konfigurator.company.de or http://test.api.konfigurator.company.de then I get to see " hello from test.api.konfigurator.company.de " as expected.

But if I call https://phpmyadmin.aws1.company.de or http://phpmyadmin.aws1.company.de then I also get " hello from test.api.konfigurator.company.de "

VHOST Config files

1. phpmyadmin.conf

    <VirtualHost *:80>
        ServerName phpmyadmin.aws1.company.de
        ServerAdmin black@company.de
        DocumentRoot /usr/share/phpmyadmin

        <Directory /usr/share/phpmyadmin>
                Options Indexes FollowSymLinks
                AllowOverride All
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/phpmyadmin_error.log
        CustomLog ${APACHE_LOG_DIR}/phpmyadmin_access.log combined

        # Redirect from http to https
        RewriteEngine On
        RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
    </VirtualHost>

    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

2. phpmyadmin_ssl.conf

    <VirtualHost *:80>
        ServerName phpmyadmin.aws1.company.de
        ServerAdmin black@company.de
        DocumentRoot /usr/share/phpmyadmin

        <Directory /usr/share/phpmyadmin>
                Options Indexes FollowSymLinks
                AllowOverride All
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/phpmyadmin_error.log
        CustomLog ${APACHE_LOG_DIR}/phpmyadmin_access.log combined

        # Example SSL configuration
        SSLEngine on
        SSLProtocol all -SSLv2
        SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
        SSLCertificateFile "/etc/ssl/certs/company/hoster_cert"
        SSLCertificateKeyFile "/etc/ssl/certs/company/hoster_key"
    </VirtualHost>

    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
  1. test_api_konfigurator.conf

     <VirtualHost *:80> ServerName test.api.konfigurator.company.de ServerAdmin black@company.de DocumentRoot /var/www/company/test.api.konfigurator.company.de/public <Directory /var/www/company/test.api.konfigurator.company.de/public> Options Indexes FollowSymLinks AllowOverride All </Directory> ErrorLog ${APACHE_LOG_DIR}/test_api_konfigurator_company_error.log CustomLog ${APACHE_LOG_DIR}/test_api_konfigurator_company_access.log combined # Redirect from http to https RewriteEngine On RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L] </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
  2. test_api_konfigurator_ssl.conf

     <VirtualHost *:443> ServerName test.api.konfigurator.company.de ServerAdmin webmaster@localhost DocumentRoot /var/www/company/test.api.konfigurator.company.de/public <Directory /var/www/company/test.api.konfigurator.company.de/public> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/test_api_konfigurator_company_error.log CustomLog ${APACHE_LOG_DIR}/test_api_konfigurator_company_access.log combined # Example SSL configuration SSLEngine on SSLProtocol all -SSLv2 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 SSLCertificateFile "/etc/ssl/certs/company/hoster_cert" SSLCertificateKeyFile "/etc/ssl/certs/company/hoster_key" </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Details:

I am using Ubuntu 22.04 LTS and Apache 2.4.52

I figured it out. My phpmyadmin_ssl.conf VHOST has Port 80 while it needs 443.

phpmyadmin_ssl.conf

<VirtualHost *:443>
    ServerName phpmyadmin.aws1.company.de
    ServerAdmin black@company.de
    DocumentRoot /usr/share/phpmyadmin

    <Directory /usr/share/phpmyadmin>
            Options Indexes FollowSymLinks
            AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/phpmyadmin_error.log
    CustomLog ${APACHE_LOG_DIR}/phpmyadmin_access.log combined

    # Example SSL configuration
    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
    SSLCertificateFile "/etc/ssl/certs/company/hoster_cert"
    SSLCertificateKeyFile "/etc/ssl/certs/company/hoster_key"
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM