
Estou executando o Apache 2.4 no Ubuntu 18.04
Estou tendo esse problema onde todos os endereços que digito na barra do navegador são redirecionados paraumdos dois sites que configurei (neste caso, sempre que digito um endereço que deve redirecionar para other-site
, é mostrado jekyll
apenas o site abaixo).
Por exemplo:
- digitar
jekyll
no navegador me mostra o site jekyll, como esperado - digitando
other-site
no navegadortambém me mostra o site do jekyll, mesmo que haja outro VirtualHost escutando esse nome
eu tenho essesdois sites separadosconfigurado como VHosts em /etc/apache2/sites-available
(amboshabilitadoatravés da a2ensite
)
jekyll.conf
<VirtualHost *:80> DirectoryIndex index.html DocumentRoot /var/www/jekyll/_site LimitRequestFieldSize 48000 <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/jekyll/_site> AllowOverride All Order allow,deny allow from all </Directory> <Directory /var/www/jekyll/_site/> Order allow,deny allow from all </Directory> ServerName jekyll ServerName http://jekyll ServerName http://localhost/jekyll ServerAdmin webmaster@localhost </VirtualHost>
outro-site.conf
<VirtualHost *:80> DirectoryIndex index.html DocumentRoot /var/www/other-site/_site LimitRequestFieldSize 48000 <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/other-site/_site> AllowOverride All Order allow,deny allow from all </Directory> <Directory /var/www/other-site/_site/> Order allow,deny allow from all </Directory> ServerName other-site ServerName http://other-site ServerName http://localhost/other-site ServerAdmin webmaster@localhost </VirtualHost>
Também adicionei essas entradas /etc/hosts
para que o localhost seja redirecionado para cada site:
127.0.0.1 localhost
127.0.0.1 localhost/jekyll
127.0.0.1 localhost/other-site
127.0.0.1 jekyll
127.0.0.1 other-site
127.0.1.1 felipe-Inspiron-7559
Responder1
O ServerName
atributo nos arquivos de configuração do Apache não precisa ser repetido, pois cada linha subsequente substituirá as anteriores.
Em vez disso, você pode usar ServerName
assim ServerAlias
:
ServerName jekyll
ServerAlias jekyll.local *.jekyll *.jekyll.local
Observe que isso é ilógico:
127.0.0.1 localhost/jekyll
127.0.0.1 localhost/other-site
Estes não são domínios (ou subdomínios), mas caminhos sob localhost
. Como resultado, apenas localhost
será observado. É por isso que não o incluí na configuração do Apache conforme mencionado acima.
Então, com isso em mente, você pode tertrêsArquivos de configuração do Apache:
⇢000-jekyll.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName jekyll
ServerAlias jekyll.local *.jekyll *.jekyll.local
DirectoryIndex index.html
DocumentRoot /var/www/jekyll/_site
LimitRequestFieldSize 48000
<Directory /var/www/jekyll/_site>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/jekyll-error.log
CustomLog ${APACHE_LOG_DIR}/jekyll-access.log combined
</VirtualHost>
⇢001-other.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName other-site
ServerAlias other-site.local *.other-site *.other-site.local
DirectoryIndex index.html
DocumentRoot /var/www/other-site/_site
LimitRequestFieldSize 48000
<Directory /var/www/other-site/_site>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/other-error.log
CustomLog ${APACHE_LOG_DIR}/other-access.log combined
</VirtualHost>
⇢999-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName localhost
ServerAlias *.localhost * *.*
DirectoryIndex index.html
DocumentRoot /var/www
LimitRequestFieldSize 48000
<Directory /var/www>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/local-error.log
CustomLog ${APACHE_LOG_DIR}/local-access.log combined
</VirtualHost>
O Apache processa o tráfego com base na ordem dos arquivos de configuração. Portanto, qualquer domínio que corresponda aos especificados 000-jekyll.conf
será tratado por esse arquivo. Se nenhuma correspondência for encontrada, 001-other.conf
será verificado. Se nenhuma correspondência for encontrada, 999-default.conf
será usado. Observe o ServerAlias
arquivo 999-default.conf
e como ele depende de curingas abertos. Isso significa que ele será tratado como um recurso genérico para o tráfego que não corresponde aos arquivos de configuração definidos.
Observação:Os arquivos de configuração do Apache foram simplificados para eliminar Directory
blocos irrelevantes e para que cada host use seus próprios logs de erros.