Configurando Virtual Hosts

Para editar o aquivo httpd-vhosts.conf, utilize o comando:

$ sudo nano /usr/local/apache2/conf/extra/httpd-vhosts.conf

Observe as configurações do arquivo httpd-vhosts.conf exemplo e realize as configurações necessárias no arquivo httpd-vhosts.conf do servidor Apache.

Ou selecione as diretivas desejadas com o mouse e as copie pressionando as teclas <CTRL> + <C>. Para colar na shell session, no arquivo aberto pelo nano, pressione as teclas <SHIFT> + <INSERT>


# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin fabiovince@gmail.com
    DocumentRoot "/usr/local/apache2/htdocs/sirius"
    ServerName sirius.guru
    ServerAlias www.sirius.guru
    ErrorLog "logs/sirius-error_log"
    CustomLog "logs/sirius-access_log" common
    <Directory "/usr/local/apache2/htdocs/sirius">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Require all granted
    </Directory>

    # Redirect www to non-www and force https
    RewriteEngine On
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
#    RewriteCond %{REQUEST_URI} !=/server-info
    RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
    # End Redirect www to non-www and force https
</VirtualHost>