Apache - создает несколько псевдонимов

Я пытаюсь установить два веб-сайта на своем сервере Apache. Каждый - www.domain.com, и другой test.domain.com. В настоящее время мой 000-default.conf файл читает следующим образом:

<VirtualHost www:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.domain.com #ServerAlias www ServerAdmin webmaster@domain.com DocumentRoot /var/www/domain.com/ # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/domain.error.log CustomLog ${APACHE_LOG_DIR}/domain.access.log combined UseCanonicalName on allow from all Options +Indexes # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> <VirtualHost test:80> DocumentRoot "/var/www/domain.com/test/" ServerName test.domain.com ServerAdmin webmaster@domain.com ErrorLog ${APACHE_LOG_DIR}/test.domain.error.log CustomLog ${APACHE_LOG_DIR}/test.domain.access.log combined UseCanonicalName on allow from all Options +Indexes </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Как, когда я использую браузер для движения в www местоположение, это показывает мне список каталогов. Однако, если я удаляю www:80 на Строке 1 и заменяю его *:80, это правильно отображает веб-страницу. Я не понимаю почему.

Кто-либо может помочь мне настроить этот 000-default.conf файл так, чтобы www перешел к "/var/www/domain.com", и тот тест переходит к "/var/www/domain.com/test"?Спасибо.

0
задан 7 June 2014 в 06:45

1 ответ

Синтаксис VirtualHost Директива

<VirtualHost addr[:port] [addr[:port]] ...> ... </VirtualHost>

, Где addr адрес виртуального хоста, не его физический путь.

, Таким образом, более безопасно использовать IP (или * подстановочный знак). Это даже говорит это в документации, что, можно использовать , полностью определил домен, но это не рекомендуется:

Из документации:

А полностью определил доменное имя для IP-адреса виртуального хоста (не рекомендуемый)

Для достижения того, что Вы спрашиваете, Вам нужна комбинация DocumentRoot и ServerName директивы. Которые, на самом деле, уже являются там.

Пример:

<VirtualHost *:80>
    DocumentRoot /var/www/domain.com/
    ServerName www.domain.com
    # Some other configs
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/domain.com/test/
    ServerName test.domain.com
    # Some other configs
</VirtualHost>
<час>

кроме того, существует другая проблема в Вашей виртуальной конфигурации хоста с apache2.4 (который поставляется по умолчанию в 14,04), allow, директива заменяется Require директива.

Это также должно быть в специальной директиве, например, Directory директива:

<Directory "/var/www/domain.com/">
    Require all granted
    Options +Indexes
</Directory>

Это - полная Виртуальная конфигурация Хоста:

<VirtualHost *:80> 
    ServerName www.domain.com
    ServerAdmin webmaster@domain.com
    DocumentRoot /var/www/domain.com/

    ErrorLog ${APACHE_LOG_DIR}/domain.error.log
    CustomLog ${APACHE_LOG_DIR}/domain.access.log combined
    UseCanonicalName on

    <Directory "/var/www/domain.com/">
        Require all granted
        Options +Indexes
    </Directory>
</VirtualHost>
2
ответ дан 7 October 2019 в 17:16

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

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