Estou tentando configurar dois subdomínios usando o apache 2.4, mas parece que há um problema que não consigo resolver.
Aqui está o arquivo de configuração do apache
<VirtualHost *:80>
ServerName www.subdomain1.myweb.com
ServerAlias subdomain1.myweb.com
DocumentRoot /srv/webapps/mywebapp
<Directory /srv/webapps/mywebapp>
AllowOverride all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName www.subdomain2.myweb.com
ServerAlias subdomain2.myweb.com
DocumentRoot /srv/webapps/mywebapp2
<Directory /srv/webapps/mywebapp2>
AllowOverride all
Options -MultiViews
Require all granted
</Directory>
Eu tentei definir o nome do servidor, mas não resolvi o problema:
ServerName www.myweb.com
E tentei usar o IP do servidor no VirtualHost, usando curingas, usando o domínio na tag VirtualHost, etc ... Tudo funcionou como desejado ainda: (
O ponto é que o servidor apache subdominio1.myweb.com , mas o subdominio.myweb.com não. A única maneira que eu não posso servir ambos os subdomínios é o último como:
<VirtualHost *:80>
ServerName www.myweb.com
ServerAlias myweb.com
DocumentRoot /srv/webapps/mywebapp2
<Directory /srv/webapps/mywebapp2>
AllowOverride all
Options -MultiViews
Require all granted
</Directory>
Assim, posso servir um subdomínio e o outro no caminho raiz, mas esse não é o comportamento desejado.
Eu acho que de alguma forma o apache está combinando a requisição com o primeiro subdiretório, não sei por que.
O Apache mostra isso como mapeamento de servidores virtuais:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server www.myweb.com
port 80 namevhost www.myweb.com
alias subdomain1.myweb.com
port 80 namevhost www.subdomain2.myweb.com
alias subdomain2.com
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/srv/http"
Main ErrorLog: "/var/log/httpd/error_log"
Mutex proxy: using_defaults
Mutex default: dir="/run/httpd/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex proxy-balancer-shm: using_defaults
PidFile: "/run/httpd/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Obrigado antecipadamente!
EDITAR
link
ServerRoot "/ etc / httpd"
Listen 80
<IfModule unixd_module>
User http
Group http
</IfModule>
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/srv/http"
<Directory "/srv/http">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "/var/log/httpd/error_log"
LogLevel warn
<Directory "/srv/http/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
# Server-pool management (MPM specific)
Include conf/extra/httpd-mpm.conf
# Multi-language error messages
Include conf/extra/httpd-multilang-errordoc.conf
# Fancy directory listings
Include conf/extra/httpd-autoindex.conf
# Language settings
Include conf/extra/httpd-languages.conf
# User home directories
Include conf/extra/httpd-userdir.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
# Various default settings
Include conf/extra/httpd-default.conf
#PHP
Include conf/extra/php5_module.conf
# Configure mod_proxy_html to understand HTML4/XHTML1
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
link
link
#
# This configuration file reflects default settings for Apache HTTP Server.
#
# You may change these, but chances are that you may not need to.
#
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 60
#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On
#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5
#
# UseCanonicalName: Determines how Apache constructs self-referencing
# URLs and the SERVER_NAME and SERVER_PORT variables.
# When set "Off", Apache will use the Hostname and Port supplied
# by the client. When set "On", Apache will use the value of the
# ServerName directive.
#
UseCanonicalName Off
#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess
#
# ServerTokens
# This directive configures what you return as the Server HTTP response
# Header. The default is 'Full' which sends information about the OS-Type
# and compiled in modules.
# Set to one of: Full | OS | Minor | Minimal | Major | Prod
# where Full conveys the most information, and Prod the least.
#
ServerTokens Full
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#
ServerSignature Off
#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off
#
# Set a timeout for how long the client may take to send the request header
# and body.
# The default for the headers is header=20-40,MinRate=500, which means wait
# for the first byte of headers for 20 seconds. If some data arrives,
# increase the timeout corresponding to a data rate of 500 bytes/s, but not
# above 40 seconds.
# The default for the request body is body=20,MinRate=500, which is the same
# but has no upper limit for the timeout.
# To disable, set to header=0 body=0
#
<IfModule reqtimeout_module>
RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500
</IfModule>
Eu tentei tocar com link mudando UseCanonicalName ou HostnameLookups para dar uma chance, mas nada funcionou até agora ...
SOLUÇÃO
Finalmente, parece que era um problema de configuração do DNS, mais do que uma configuração de host virtual.
Usando neste caso domínios do Google, apenas adicionando um registro de recurso personalizado para cada subdomínio e apontando para o endereço IP que manipulará a solicitação (no meu caso, o mesmo servidor, que manipulará a solicitação com os hosts virtuais como OP mostra), fez o trabalho.
Obrigado a todos!