Apache - cria vários aliases

0

Estou tentando configurar dois sites no meu servidor Apache. Um é www.domain.com e o outro é test.domain.com. Atualmente, meu arquivo 000-default.conf lê o seguinte:

<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 [email protected] 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 [email protected] 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

Da mesma forma, quando eu uso um navegador para ir ao local do www, ele mostra uma lista de diretórios. No entanto, se eu remover o www: 80 na Linha 1 e substituí-lo por *: 80, ele exibirá corretamente a página da Web. Eu não entendo o porquê.

Alguém pode me ajudar a configurar esse arquivo 000-default.conf para que o www vá para "/var/www/domain.com" e esse teste vá para "/var/www/domain.com/test"? Obrigado.

    
por mc3mcintyre 07.06.2014 / 02:45

1 resposta

1

A sintaxe da VirtualHost diretiva é

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

Em que addr é o endereço do host virtual, não seu caminho físico.

Portanto, é mais seguro usar um IP (ou o curinga * ). Ele até diz na documentação que, você pode usar um domínio totalmente qualificado , mas não é recomendado:

Da documentação:

A fully qualified domain name for the IP address of the virtual host (not recommended)

Para alcançar o que você está pedindo, você precisa de uma combinação das diretivas DocumentRoot e ServerName . Que, de fato, já estão lá.

Exemplo:

<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>

Além disso, há outro problema em sua configuração de host virtual, como no apache2.4 (que é fornecido por padrão em 14.04), a diretiva allow é substituída pela diretiva Require .

Também precisa estar dentro de uma diretiva especial, por exemplo, a diretiva Directory :

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

Esta é uma configuração completa do Host Virtual:

<VirtualHost *:80> 
    ServerName www.domain.com
    ServerAdmin [email protected]
    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>
    
por Dan 07.06.2014 / 09:22