不能configuration两个子域apache 2.4

我正在尝试使用apache 2.4configuration两个子域,但似乎有一个问题,我无法解决。

这里是Apache的configuration文件

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

我试着定义ServerName,但没有解决问题:

 ServerName www.myweb.com 

并尝试在VirtualHost中使用服务器IP,使用通配符,在VirtualHost标签中使用域…等等任何工作如需要:

重点是,Apache服务器subdomain1.myweb.com ,但subdomain.myweb.com不。 唯一的办法,我不能服务这两个子域它是设置最后一个:

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

所以我可以服务一个子域和另一个在根path,但这不是所需的行为。

我想这是不知何故apache它匹配与第一个子域的请求,不知道为什么。

Apache将其显示为虚拟服务器映射:

  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 

先谢谢你!

编辑

httpd.conf基本上是默认的configuration,因为我从一开始就遇到这个问题,除了虚拟主机,我还没有configuration任何东西。

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> 

http-vhosts.conf与最初的问题相同

的httpd-default.conf

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

我试图玩http-default.conf改变UseCanonicalNameHostnameLookups给他们一枪,但没有工作到目前为止…

最后看来,这是一个DNSconfiguration问题,多于一个虚拟主机configuration。

在这种情况下,使用Google域,只需为每个子域添加一个自定义资源logging,并指向将处理请求的IP地址(在我的情况下是同一台服务器,将以OP显示的虚拟主机处理请求) ,使其工作。

谢谢你们!

我注意到在你的子域2中,你没有包含。 不知道这只是在这里的configuration,或者你的。 你有服务httpd重新加载(或服务apache2重新加载取决于操作系统)是你的DNS指向你的IP使用这些域名?

TL; DR删除www

www已经是example.com的一个子域名。

所以你当然可以定义你的原始域的第三或第四级域名。 但是你很可能不想要一些东西.www.yourdomain.com作为你的子域名。

你可能想要的是subdomain.yourdomain.com,因此只需删除wwww。

还没有testing你的configuration,所以我不知道其余的。