我在一台计算机上有两个虚拟主机test.com
和example.com
。 test.com
可以正常工作,但是example.com
服务器可以重定向到万维网。配置与其他虚拟主机相同的代码。找不到语法或语义错误。 Apache工作正常。 error.log
中没有消息。我不明白为什么一个虚拟主机有效而第二个虚拟主机无效。 test.com.conf
中的文件example.com.conf
和/etc/apache2/sites-available
:
<VirtualHost *:80>
DocumentRoot /var/www/test.com/public_html
ServerName test.com
ServerAlias www.test.com
ServerAdmin anymail@gmail.com
ErrorLog /var/www/test.com/log/error.log
CustomLog /var/www/test.com/log/access.log combined
</VirtualHost>
########################################################################
<VirtualHost *:80>
DocumentRoot /var/www/example.com/public_html
ServerName example.com
ServerAlias www.example.com
ServerAdmin anymail@yahoo.com
ErrorLog /var/www/example.com/log/error.log
CustomLog /var/www/example.com/log/access.log combined
</VirtualHost>
apache2.conf
:
DefaultRuntimeDir ${APACHE_RUN_DIR}
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "^\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
/etc/hosts
:
127.0.0.1 test.com
127.0.0.1 example.com
127.0.0.1 localhost
diff
来自/test.com/.../index.php
和example.com/.../index.php
9c9
< echo "Welcome to example.com";
---
> echo "Welcome to test.com";
@elitepc @akshaypjoski是的,我曾经使用过a2ensite
工具,并且在更改cofig文件后总是重新启动服务器。
@DrCord,@ Nix3500现在,该问题看起来又一个了。我将确保服务器正常运行。我输入nmap -A example.com
并在输出中看到127.0.0.1
。之后,我输入标准的shell perl GET脚本,并在输出中显示我的html页面。但!网络浏览器(Mozilla,Chromium)通过example.com
的IP地址为我提供了页面93.184.216.34
。我很尴尬。
总而言之,我现在要讲下:从shell没问题;从网络浏览器test.com
正常工作,并且example.com
从93.184.216.34
域获得。