简体   繁体   English

同一个apache服务器的多个域名

[英]Multiple domain names for the same apache server

I'm working on a little project where an apache server with php running on it runs several different websites on it. 我正在开发一个小项目,其中运行php的apache服务器上运行着几个不同的网站。 I want to give these sites domains. 我想给这些网站域名。

Can I put my ip followed by and identifying number ex: 192.16.0.1/?sumNum into the DNS to differentiate between witch website is being asked for? 我可以将我的ip后跟并识别号码ex: 192.16.0.1/?sumNum到DNS中以区分巫婆网站被要求吗? They all have the same index.php homepage file. 它们都有相同的index.php主页文件。

Can I put my IP followed by and identifying number ex: 192.16.0.1/?sumNum into the DNS to differentiate between which website is being asked for? 我可以将我的IP后跟并识别号码ex:192.16.0.1/?sumNum到DNS中以区分要求的网站吗?

No, what you are talking about is called Named based Virtual Hosting in Apache . 不,你所说的是在Apache中称为基于命名的虚拟主机 As it says in the Apache documentation: 正如Apache文档中所述:

With name-based virtual hosting, the server relies on the client to report the hostname as part of the HTTP headers. 使用基于名称的虚拟主机,服务器依赖客户端将主机名报告为HTTP标头的一部分。 Using this technique, many different hosts can share the same IP address. 使用此技术,许多不同的主机可以共享相同的IP地址。

You start by registering your domains in the DNS with a registrar, such as Google Domains. 首先,您可以通过注册商(例如Google Domains)在DNS中注册您的域名。 Then, through the registrar, you will create a DNS A record, for each domain pointing to the same IP address. 然后,通过注册器,您将为每个指向相同IP地址的域创建DNS A记录。

Within Apache, when you set up the named based virtual hosting, you are effectively saying, when you see this domain name, go to this particular directory on this computer to serve up the files (which are your HTML/PHP files). 在Apache中,当您设置基于命名的虚拟主机时,您实际上是在说,当您看到此域名时,请转到此计算机上的此特定目录以提供文件(这是您的HTML / PHP文件)。 But in your case, you can point each of those virtual hosts to the same directory. 但在您的情况下,您可以将每个虚拟主机指向同一目录。

You can then use $_SERVER['HTTP_HOST'] within PHP to retrieve the domain coming in and do what you want to do differently for each domain. 然后,您可以在PHP中使用$_SERVER['HTTP_HOST']来检索进入的域,并为每个域执行不同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM