我的服务器拥有两个IP 192.168.1.90和192.168.1.99我希望nginx在192.168.1.99和Apache上侦听192.168.1.90我还需要在apache上托pipe多个虚拟主机。
尝试修改apache的ports.conf
NameVirtualHost 192.168.1.90: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>
然后我在Apache中托pipe了一个虚拟主机
<VirtualHost 192.168.1.90:80> DocumentRoot /home/webmaster/www/thefactor/ ServerName www.XYZ.com ServerAlias XYZ.cu.com # Other directives here </VirtualHost>
问题是所有的stream量,所有的请求来到192.168.1.90而不考虑域名加载XYZ.com。 即:如果我指向ABC.com 192.168.1.90然后当我浏览它,它加载XYZ.com页面,但地址栏中的地址将保持ABC.com,所以它不是一个redirect。
任何想法为什么发生这种情况
您定义的第一个虚拟主机将是“默认”主机。 因此,对其他地方未configuration的域的所有请求都将转到该第一个主机。
如果您希望请求未在服务器上configuration的域,但无论如何将其定向到忽略域,则需要创build一个单独的“全部捕获”虚拟虚拟主机,该虚拟主机只拒绝所有请求,并在其他主机之前列出。
<VirtualHost 192.168.1.90:80> #Dummy Host denies all accesses. Order Allow, Deny Deny from all </VirtualHost> <VirtualHost 192.168.1.90:80> DocumentRoot /home/webmaster/www/thefactor/ ServerName www.XYZ.com ServerAlias XYZ.cu.com # Other directives here </VirtualHost>
您需要将Listen指令的范围缩小到192.168.1.90
Listen 192.168.1.90:80
Listen 192.168.1.90:443
否则Apache将监听所有IP(并且传入的请求命中默认的虚拟主机)。