Apache vhost加载了不正确的文档根目录
我的问题是Apache随机加载一个非默认vhost,而不是我要求它加载的域。我已经尝试了我在这个网站上找到的每一个解决方案,通过搜索,但似乎没有什么能解决这个问题 背景:Apache vhost加载了不正确的文档根目录,apache,ubuntu,Apache,Ubuntu,我的问题是Apache随机加载一个非默认vhost,而不是我要求它加载的域。我已经尝试了我在这个网站上找到的每一个解决方案,通过搜索,但似乎没有什么能解决这个问题 背景: 这是一个托管在流行云平台上的虚拟服务器 全局apache conf文件不包含VirtualHost定义,下面的配置文件包含正确(Include sites enabled/*.conf) Ubuntu 16.04上的Apache 2.4 我把每个域都放在自己的conf文件中,但这也不起作用 出于某种原因,Apache选择了d
- 这是一个托管在流行云平台上的虚拟服务器
- 全局apache conf文件不包含VirtualHost定义,下面的配置文件包含正确(Include sites enabled/*.conf)
- Ubuntu 16.04上的Apache 2.4
- 我把每个域都放在自己的conf文件中,但这也不起作用
- 出于某种原因,Apache选择了domain3.com作为默认值
- 当我在服务器上执行
时,它返回domain3.com的内容curl localhost
- 下面vhost中唯一排除的是一些似乎不会引起任何问题的SSL定义
- ServerName在apache.conf中定义为
localhost
- 下面的虚拟主机保存在
/etc/apache2/sites enabled/000 default.conf
- 我似乎无法真正阻止apache。执行
,然后执行service apache2 stop
会将进程标识为非活动,但我仍然可以在domain1/2/3.com下加载页面。我所做的一切都没有任何效果service apache2 status
- 现在有3种方法可以访问apache。有些似乎有效,有些则无效<代码>/etc/init.d/apache2,
,服务apache2
apache2ctl
- 它只在大约50%的时间里加载错误的站点
NameVirtualHost *:80
# domain1.com
<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.domain1.com
ServerAlias domain1.com
UseCanonicalName Off
ServerAdmin webmaster@localhost
DocumentRoot /var/www/domain1.com/
<Directory /var/www/domain1.com>
Options Indexes FollowSymLinks
AllowOverride All
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>
# domain3.com
<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.domain3.com
ServerAlias domain3.com
ServerAlias domain3.net
ServerAlias www.domain3.net
UseCanonicalName Off
ServerAdmin webmaster@localhost
DocumentRoot /var/www/domain3.com/
<Directory /var/www/domain3.com>
Options Indexes FollowSymLinks
AllowOverride All
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}/cq2_error.log
CustomLog ${APACHE_LOG_DIR}/cq2_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>
# domain2.com
<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.domain2.com
ServerAlias domain2.com
UseCanonicalName Off
ServerAdmin webmaster@localhost
DocumentRoot /var/www/domain2.com/
<Directory /var/www/domain2.com>
Options Indexes FollowSymLinks
AllowOverride All
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>
您的配置看起来不错,您所描述的奇怪之处似乎与外部问题有关,比如发行版脚本,或者其他什么…,因此尝试仅使用apachectl来停止/启动,如果发行版没有太大变化,这是您将发现的管理httpd服务器启动/停止等的最“正式”的方法,另外,这是你现在唯一能提供正确信息的东西 此外,在您的配置中,domain3.com永远不会是默认的virtualhost,即使您错误地定义了服务器名。所以,您很可能看到其他“服务/服务器”正在发送给您什么 答复:
Use apachectl only until you fix your discro script issues
在Ubuntu 16.04上,你有
systemd
。。因此,与apache交互的正确方法是使用systemctl apache2
我建议杀死每个apache进程,然后尝试使用systemctl start apache2
再次启动它
此外,为了确保首先加载默认域,我通常将其配置文件重命名为
000 domain.conf
。。然后添加其他域,每个文件一个,在Apache选择随机站点时根本没有数字前缀:
当您执行curl localhost
时,它可能会发送一个未定义Host:
的HTTP头,因为它的行为类似于您直接在浏览器中键入服务器的IP。HTTP请求中的Host:
头是Apache与ServerName
和ServerAlias
匹配的字段,试图找到匹配项以加载相应的DocumentRoot
因此,在这种情况下,如果您没有默认的主机设置,并且有一个空主机:进入,那么Apache将随机选择一个站点(我在我的开发服务器上重新创建了这个行为,只是为了验证)
最好将000-default.conf设置为您的“一网打尽”,并决定在发生这种情况时应该做什么,比如重定向到您的某个站点,或者重定向到一个简单的php文件,该文件只是回应一些平淡的内容。然后为每个站点设置单独的conf文件以保持组织
如果您有正确指向服务器的DNS记录,则只有当机器人程序测试IP时才会触发默认设置 只是想在这里说清楚,你不会把它命名为
000 default.conf
?但是如果域是http://apple.com
?这一次实际上解决了我的问题。由于僵尸进程,apache似乎没有完全重新启动。清除旧的apache进程会导致正确地重新加载配置,现在一切都正常了。谢谢我知道,这就是为什么它如此奇怪。
Use apachectl only until you fix your discro script issues