Apache始终服务于第一个虚拟主机

我几次看到这个问题,但令人惊讶的是没有解决scheme为我工作:

  • 是的,我用“sudo a2ensite com.secondwebsite.conf”
  • 是的,我用“sudo /etc/init.d/apache2 reload”
  • 是的,我用“sudo /etc/init.d/apache2 restart”
  • 是的,我已经尝试将两个虚拟主机放入一个文件(/ etc / apache2 / sites-available / default),在其上添加“NameVirtualHost *:80”并从“/etc/apache2/ports.conf”
  • 是的,我用“sudo chmod 777 / var / www / secondwebsite”

无论我做什么,secondwebsite.com不断显示firstwebsite.com。 有没有人有任何想法可能造成这种情况?

这里是我的“/ etc / apache2 / sites-available / default”

<VirtualHost *:80> ServerAdmin [email protected] ServerName firstwebsite.com ServerAlias www.firstwebsite.com DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /static /home/user/firstwebsite/firstwebsite/static <Directory /home/user/firstwebsite/firstwebsite/static> Order allow,deny Allow from all </Directory> Alias /media /home/user/firstwebsite/firstwebsite/site_media/media <Directory /home/user/firstwebsite/firstwebsite/site_media/media> Order allow,deny Allow from all </Directory> <Directory /home/user/firstwebsite/firstwebsite> Order allow,deny Allow from all </Directory> WSGIDaemonProcess firstwebsite WSGIProcessGroup firstwebsite WSGIScriptAlias / /home/user/firstwebsite/firstwebsite/wsgi.py </VirtualHost> 

我的“/etc/apache2/sites-available/com.secondwebsite.conf”

  <VirtualHost *:80> ServerAdmin [email protected] ServerName secondwebsite.com ServerAlias www.secondwebsite.com DocumentRoot /var/www/secondwebsite/public_html ErrorLog ${APACHE_LOG_DIR}/secondwebsite_error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 

我的“/etc/apache2/ports.conf”

  # If you just change the port or add more ports here, you will likely also # have to change the VirtualHost statement in # /etc/apache2/sites-enabled/000-default # This is also true if you have upgraded from before 2.2.9-3 (ie from # Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and # README.Debian.gz NameVirtualHost *:80 Listen 80 <IfModule mod_ssl.c> # If you add NameVirtualHost *:443 here, you will also have to change # the VirtualHost statement in /etc/apache2/sites-available/default-ssl # to <VirtualHost *:443> # Server Name Indication for SSL named virtual hosts is currently not # supported by MSIE on Windows XP. Listen 443 </IfModule> <IfModule mod_gnutls.c> Listen 443 </IfModule> 

sudo / usr / sbin / apache2ctl -S的结果

  VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: *:80 is a NameVirtualHost default server firstwebsite.com (/etc/apache2/sites-enabled/000-default:1) port 80 namevhost firstwebsite.com (/etc/apache2/sites-enabled/000-default:1) port 80 namevhost secondwebsite.com (/etc/apache2/sites-enabled/com.secondwebsite.conf:1) Syntax OK 

您的服务器别名似乎不起作用,因为它们不是由命令/usr/sbin/apache2ctl -S因为它应该类似于

 VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: *:80 is a NameVirtualHost default server firstwebsite.com (/etc/apache2/sites-enabled/000-default:1) port 80 namevhost firstwebsite.com (/etc/apache2/sites-enabled/000-default:1) alias www.firstwebsite.com port 80 namevhost secondwebsite.com (/etc/apache2/sites-enabled/com.secondwebsite.conf:1) alias www.secondwebsite.com Syntax OK 

请提供您的Apache版本。

在第二个虚拟主机中也没有/ var / www / secondwebsite / public_html的 “目录”configuration。 试着把一个。

至于我的经验,这可能发生在以下情况:

firstsite.com有DNS 1.2.3.4和IP在虚拟主机1.2.3.4或*

secondsite.com有dns 1.2.3.4,vhost中的ip是1.2.3.5。

1.2.3.4和1.2.3.5都是有问题的服务器的ips,而且apache同时在两个ips上监听。

但是至于你提供的几个日志和细节,很难发现这是否真的如此。