简体   繁体   English

具有2个IP地址的Apache上基于名称的虚拟主机

[英]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.

相关问题 如何使用 3 个站点设置 Apache:两个基于名称的虚拟主机和一个通过 IP 地址 - How to set up Apache with 3 sites: Two name based virtual hosts and one via the IP address 使用 Laravel 和 Apache 的虚拟主机,无法将 ip 设置为网站名称 - Virtual Hosts with Laravel and Apache, cannot set ip to website name 局域网上基于apache,DNS,基于访问名称的虚拟主机,而无需在每台计算机的“主机”文件中键入IP和服务器名称 - apache, DNS, access name based virtual host on LAN without typing the IP and server name at the “hosts” file of every computer 基于名称的虚拟主机 - Name based virtual hosts 基于IP和域的虚拟主机 - IP and Domain Based Virtual Hosts Apache上基于端口的虚拟主机 - Port based virtual hosts on apache 通过本地IP地址打开多个虚拟主机 - Open multiple virtual hosts by local IP address Apache虚拟主机直接IP访问 - Apache Virtual Hosts direct IP Access 一个IP地址和通配符证书,用于多个虚拟主机(Windows,Apache 2.4.2,OpenSSL 1.0.2e) - One IP Address and Wildcard Certificate for multiple Virtual Hosts (Windows, Apache 2.4.2, OpenSSL 1.0.2e) 如何通过 AWS 在 Apache 服务器中托管来自同一 IP 地址的多个虚拟主机? - how to host multiple virtual hosts from same IP address in Apache server over AWS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM