Поддомен Apache2 не загружает содержимое (зеркала основного домена)

У меня есть веб-сервер Apache2, работает на Ubuntu прямо сейчас. Основной домен работает нормально ( Example.com ). Я пытаюсь добавить поддомен ( subdomain.example.com ), но я не могу заставить его работать.

DNS все установлена ​​правильно. Я могу пинг subdomain.example.com . Но когда я ориентируюсь на URL, он просто отражает основной домен в example.com .

В / etc / apache2 / доступных сайтов , у меня есть два файла: 001-subdomain.example.com.conf и 999-Example.com.conf .

001-subdomain.example.com.conf выглядит так:

<VirtualHost *:80>
    ServerAdmin me@example.com

    DocumentRoot /var/www/subdomain.example.com/html
    DirectoryIndex index.php index.html

    ServerName subdomain.example.com
    ServerAlias subdomain.example.com *.subdomain.example.com

    ErrorLog ${APACHE_LOG_DIR}/subdomain-error.log
    CustomLog ${APACHE_LOG_DIR}/subdomain-access.log combined
    
</VirtualHost>

<VirtualHost *:443>

    ServerAdmin me@example.com

    DocumentRoot /var/www/subdomain.example.com/html
    DirectoryIndex index.php index.html

    ServerName subdomain.example.com
    ServerAlias subdomain.example.com *.subdomain.example.com
    
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    SSLEngine on

    SSLCertificateFile      /etc/ssl/certs/apache-selfsigned.crt
    SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
                    SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
                    SSLOptions +StdEnvVars
    </Directory>

    BrowserMatch "MSIE [2-6]" \
                   nokeepalive ssl-unclean-shutdown \
                   downgrade-1.0 force-response-1.0
</VirtualHost>

<Directory /var/www/subdomain.example.com/html>
    Options FollowSymLinks
    AllowOverride All

    Order Allow,Deny
    Allow From All
</Directory>

999-example.com.conf Похоже:

<VirtualHost *:80>
    ServerAdmin me@example.com
    
    DocumentRoot /var/www/example.com/html
    DirectoryIndex index.php index.html

    ServerName example.com
    ServerAlias example.com *.example.com *.*
    
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    
</VirtualHost>

<VirtualHost *:443>

    ServerAdmin me@example.com
    
    DocumentRoot /var/www/example.com/html
    DirectoryIndex index.php index.html

    ServerName example.com
    ServerAlias example.com *.example.com *.*
    
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    SSLEngine on

    SSLCertificateFile      /etc/ssl/certs/apache-selfsigned.crt
    SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
                    SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
                    SSLOptions +StdEnvVars
    </Directory>

    BrowserMatch "MSIE [2-6]" \
                   nokeepalive ssl-unclean-shutdown \
                   downgrade-1.0 force-response-1.0
</VirtualHost>

<Directory /var/www/example.com/html>
    Options FollowSymLinks
    AllowOverride All

    Order Allow,Deny
    Allow From All
</Directory>

Однако поддомен до сих пор не содержит содержимого Отказ Это просто отражает основной сайт. И правильные файлы в /var/www/subdomain.example.com/html .

Как я могу настроить поддомен, чтобы загрузить правильный контент?

0
задан 5 March 2021 в 05:26

1 ответ

Apache загружает вещи в алфавитном порядке, поэтому, если конфигурация поддомена будет после основного домена, есть большая вероятность того, что запросы к поддомену неправильно перенаправляются на первичный. Обычно я делаю с Apache, чтобы основной сайт был последним в списке конфигурационных файлов. Например:

/etc/apache/sites-enabled$ ll

drwxr-xr-x 2 root root 4096  2月  3 16:33 ./
drwxr-xr-x 8 root root 4096  1月 22 13:07 ../
lrwxrwxrwx 1 root root   34  1月 28 21:49 002-subdomain1.conf -> ../sites-available/002-subdomain1.conf
lrwxrwxrwx 1 root root   33  2月  3 16:33 003-subdomain2.conf -> ../sites-available/003-subdomain2.conf
lrwxrwxrwx 1 root root   32  1月 22 17:39 999-primary.conf -> ../sites-available/999-primary.conf

Каждый из конфигурационных файлов содержит как ServerName, так и ServerAlais строку с подстановочными знаками, где это уместно. Это означает, что файл Subdomain .conf может выглядеть следующим образом:

<VirtualHost *:80>
        ServerAdmin my@email.address
        DocumentRoot /var/www/subdomain1/html

        ServerName sub1.domain.com
        ServerAlias sub1.domain.com *.sub1.domain.com
        DirectoryIndex index.php index.html

        ErrorLog ${APACHE_LOG_DIR}/subdomain1-error.log
        CustomLog ${APACHE_LOG_DIR}/subdomain1-access.log combined
</VirtualHost>

<VirtualHost *:443>...</VirtualHost>

<Directory /var/www/subdomain1/html>
        Options FollowSymLinks
        AllowOverride All

        Order Allow,Deny
        Allow From All
</Directory>

Основной (и стандартный) сайт, будет иметь файл .conf, который выглядит похожим, но с более широким списком в ServerAlias, чтобы улавливать любой неожиданный трафик:

        ServerAlias domain.com *.domain.com *.*

Это работало довольно хорошо на протяжении многих лет

2
ответ дан 18 March 2021 в 23:29

Другие вопросы по тегам:

Похожие вопросы: