Apache2 Virtualhost leva-me ao diretório raiz

0

Eu tenho um host virtual criado sob /etc/apache2/sites-available chamado attrave.com.conf

Aqui está o código para esse arquivo host virtual (somente código relevante anexado):

ServerName attrave.com
ServerAdmin [email protected]
ServerAlias www.attrave.com
DocumentRoot /var/www/attrave.com

<Directory />
        Options FollowSymLinks
        AllowOverride None
</Directory>
<Directory /var/www/attrave.com>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>

Gostaria de poder acessar o site www.attrave.com também por apenas attrave.com .

Atualmente, quando eu navego para attrave.com , ele me leva ao diretório /var/www/ quando ele realmente deve me levar para a pasta attrave.com real. Quando incluo www. , tudo funciona, mas isso é frustrante.

EDITAR: Aqui está meu arquivo host virtual atualizado: (ISTO AINDA NÃO FUNCIONA)

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *: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.attrave.com
ServerAdmin [email protected]
ServerAlias www.attrave.com
DocumentRoot /var/www/attrave.com

<Directory />
        Options FollowSymLinks
        AllowOverride None
</Directory>
<Directory /var/www/attrave.com>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>

UPDATE 2:

Eu tentei usar todas as suas sugestões e ainda não consigo fazer o site funcionar em "attrave.com" . Ele funciona em "www.attrave.com" .

Estou anexando texto de conteúdo relevante que, esperamos, permita que você tenha mais informações sobre esse assunto.

  • Attrave.com.conf (arquivo host virtual)

    DocumentRoot /var/www/attrave.com
    ServerName attrave.com
    ServerAlias attrave.com www.attrave.com
    ServerAdmin [email protected]
    
    
    <Directory /var/www/attrave.com>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>
    
  • arquivo / etc / hosts

    # Your system has configured 'manage_etc_hosts' as True.
    # As a result, if you wish for changes to this file to persist
    # then you will need to either
    # a.) make changes to the master file in /etc/cloud/templates/hosts.tmpl
    # b.) change or remove the value of 'manage_etc_hosts' in
    #     /etc/cloud/cloud.cfg or cloud-config from user-data
    
    127.0.0.1 localhost
    
  • arquivo Apache2.conf

     <Directory />
      Options FollowSymLinks
     AllowOverride None
      Require all denied
     </Directory>
    
    <Directory /usr/share>
     AllowOverride None
     Require all granted
    </Directory>
    
    <Directory /var/www/>
     Options Indexes FollowSymLinks
     AllowOverride None
     Require all granted
     </Directory>
    
     #<Directory /srv/>
     #  Options Indexes FollowSymLinks
     #   AllowOverride None
     #   Require all granted
    #</Directory>
    
por mat 23.04.2015 / 15:55

2 respostas

0

Na sua configuração original:

ServerName attrave.com
ServerAdmin [email protected]
ServerAlias www.attrave.com
DocumentRoot /var/www/attrave.com

<Directory />
        Options FollowSymLinks
        AllowOverride None
</Directory>
<Directory /var/www/attrave.com>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>

Você tem um ServerAlias , que é definido apenas como www.attrave.com . Eu recomendaria adicionar attrave.com a essa lista assim:

ServerAlias attrave.com www.attrave.com

Além disso, eu recomendaria alterar a ordem das principais opções de configuração da seguinte forma:

DocumentRoot /var/www/attrave.com
ServerName attrave.com
ServerAlias www.attrave.com
ServerAdmin [email protected]

Além disso, esse chunklet de config é inútil do que estou vendo, pois a diretiva <Directory /var/www/attrave.com> do núcleo é o que está sendo usado para DocumentRoot :

<Directory />
        Options FollowSymLinks
        AllowOverride None
</Directory>

Se nada disso não mudar alguma coisa, então parece que há algo mais errado em sua configuração principal do Apache.

    
por 23.04.2015 / 17:01
-1

você tentou:

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot /var/www/attrave.com
    Servername attrave.com
    # Other directives here
</VirtualHost>
    
por 23.04.2015 / 16:01