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.

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

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable