[英]Name Based Virtual Hosts on Apache with 2 IP Address
I have 2 IP addresses. 我有2个IP地址。 It is basically for SSL but let's assume that I want example1.com and example3.com work at IP 1.1.1.1 and example2.com works at IP 2.2.2.2.
它基本上是针对SSL的,但是假设我希望example1.com和example3.com在IP 1.1.1.1上工作,而example2.com在IP 2.2.2.2上工作。
I should be missing something, somewhere. 我应该在某处丢失一些东西。 I have basically following settings related with this in the configuration files - I did read and apply the same thing in Apache documentation as well as many other sources.
我基本上在配置文件中有以下与此相关的设置-我确实阅读并应用了Apache文档以及许多其他资源中的相同内容。
Listen 80
<VirtualHost *:80>
ServerName example1.com
# ...
</VirtualHost>
<VirtualHost *:80>
ServerName example3.com
# ...
</VirtualHost>
<VirtualHost 2.2.2.2:80>
ServerName example2.com
# ...
</VirtualHost>
I have example2.com pointed to 2.2.2.2 and and the others to 1.1.1.1 in DNS records. 我在DNS记录中有example2.com指向2.2.2.2,其他指向1.1.1.1。
I can go to example1.com and example3.com successfully but example2.com goes to default server, which is example1.com for this sample since it was entered first in the configuration. 我可以成功进入example1.com和example3.com,但是example2.com转到默认服务器,因为此示例是在配置中首先输入的,因此它是此示例的example1.com。
Another weirdness: keeping DNS same for example2.com but change vhost config to be *:80 and it opens the website and server ip is reported as 1.1.1.1 as I can get from the web script to see what's going on. 另一个怪异之处:在example2.com上将DNS保持不变,但将vhost config更改为*:80,这将打开网站,并且服务器IP报告为1.1.1.1,因为我可以从Web脚本中了解发生了什么。
And another one: Even I keep only example2.com domain in the configuration and remove others, it still doesn't work with the IP. 还有一个:即使我仅在配置中保留example2.com域,并删除其他域,该域仍无法与IP一起使用。 As I tried to mention, if I enter 2.2.2.2, it successfully access to the server via this IP.
正如我试图提到的那样,如果输入2.2.2.2,它将通过此IP成功访问服务器。
Could someone please help me to solve this problem which is obviously caused by something I am doing wrong or missing. 有人可以帮我解决这个问题,这显然是由于我做错了或丢失了。
Thank you. 谢谢。
I had DHCP enabled in the server. 我在服务器中启用了DHCP。 I changed it to be static networking and it all worked.
我将其更改为静态网络,并且一切正常。
I edited /etc/sysconfig/network-scripts/ifcfg-eth0 as necessary to add static IPs and disabled Auto Configure Network option for my server. 我根据需要编辑了/ etc / sysconfig / network-scripts / ifcfg-eth0以添加静态IP,并为服务器禁用了“自动配置网络”选项。 It is a Linode server and required settings explained here - just in case someone else needs: https://www.linode.com/docs/networking/linux-static-ip-configuration
这是一台Linode服务器,并在此处说明了所需的设置-以防万一其他人需要: https : //www.linode.com/docs/networking/linux-static-ip-configuration
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.