duanhuang1967 2017-01-05 07:25
浏览 67
已采纳

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

I'm working on a little project where an apache server with php running on it runs several different websites on it. 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? They all have the same index.php homepage file.

  • 写回答

1条回答 默认 最新

  • donglan6777 2017-01-05 09:58
    关注

    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?

    No, what you are talking about is called Named based Virtual Hosting in Apache. As it says in the Apache documentation:

    With name-based virtual hosting, the server relies on the client to report the hostname as part of the HTTP headers. Using this technique, many different hosts can share the same IP address.

    You start by registering your domains in the DNS with a registrar, such as Google Domains. Then, through the registrar, you will create a DNS A record, for each domain pointing to the same IP address.

    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). 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备