Apache2 agora apontando para nova página padrão

0

Meu servidor Apache2 tem uma nova página padrão: Apache2 Ubuntu Default Page (localizada em /var/www/html/index.html )

Todos os arquivos servidos pelo meu servidor web estão em: /opt/lampp/htdocs folder.

Por que essa mudança aconteceu e como corrigi-la?

    
por JohnnyBizzle 06.12.2016 / 11:27

1 resposta

3

O Apache2 do repositório do Ubuntu obtém seu local padrão em /etc/apache2/sites-available .

A configuração da página padrão é o arquivo 000-default.conf nesse local.

Você pode modificar essa página ou usá-la como modelo e criar seu próprio arquivo de configuração. Se você quiser ter uma página com a localização de /opt/lampp/htdocs como rota do servidor, você pode fazer isso dessa maneira:

1) Copie o arquivo 00-default.conf para um novo nome. Para um método fácil de lembrar, você pode chamar o nome do arquivo, mywebsite.conf para ter a configuração para www.mywebsite.conf .

Agora edite esta nova página com estas alterações:

Alterar de:

<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.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # 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}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

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

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

mudar para:

<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.mywebsite.com
        ServerAlias mywebsite.com

        ServerAdmin webmaster@localhost
        DocumentRoot /opt/lampp/htdocs

        # We must also allow access to the new root directory; by
        # default only access to /var/www is allowed.
        <Directory /opt/lampp/htdocs>
            Require all granted
        </Directory>

        # 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}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

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

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

Depois de criar o host virtual do seu site, ative essa nova configuração com:

$ sudo a2ensite mywebsite.conf

O sistema solicitará que você reinicie o servidor para que as alterações entrem em vigor, o que você pode fazer com:

$ sudo systemctl restart apache2

As duas alterações importantes são:

  1. Nome do servidor
  2. DocumentRoot

Agora você pode acessar seu site com o nome dado nas diretivas ServerName ou ServerAlias.

Deixei os comentários no exemplo de arquivos de configuração para mostrar as opções que podem ser ativadas removendo a opção "#" desejada. Além disso, os comentários são um recurso valioso que explica as opções de configuração.

    
por L. D. James 06.12.2016 / 12:02