【问题标题】:Apache Server Hosting Multiple Sites Using Different Directories (CentOS)使用不同目录托管多个站点的 Apache 服务器 (CentOS)
【发布时间】:2015-04-19 01:32:47
【问题描述】:

请帮我在 apache 服务器上设置正确的配置。我不知道它叫什么,但我想在我的服务器(Amazon EC2 (CentOS) 服务器)上设置多个站点。它还没有域名。

我已经安装了所需的软件,包括 php(检查 phpinfo.php)。它工作正常。

现在,我想在我的机器上托管两个不同的基于 php 的站点。
假设,我的 IP 地址是 x.y.z.a

目录:
/var/www/html/crm
/var/www/html/crmpanel
/var/www/html/mysite

在我的 httpd.conf 中,我有:

名称虚拟主机 *:80
服务器名称 x.y.z.a
DocumentRoot "/var/www/html"

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName x.y.z.a
    ServerAlias x.y.z.a

    DocumentRoot "/var/www/html/crm"

    ErrorLog  /var/log/httpd/error_log
    CustomLog /var/log/httpd/access_log combined

</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName x.y.z.a
    ServerAlias x.y.z.a

    DocumentRoot "/var/www/html/crmpanel"

    ErrorLog  /var/log/httpd/error_log
    CustomLog /var/log/httpd/access_log combined

</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName x.y.z.a
    ServerAlias x.y.z.a

    DocumentRoot "/var/www/html/mysite"

    ErrorLog  /var/log/httpd/error_log
    CustomLog /var/log/httpd/access_log combined

</VirtualHost>


如果我运行“httpd -S”,它会返回“语法 OK”。 Apache 服务器启动时没有任何错误。

请帮助我了解我的配置有什么问题。

【问题讨论】:

  • 我希望您在每个 VirtualHost 配置中都有不同的服务器名称。一个用于 site1.com,另一个用于 site2.com
  • 不,我不知道。我还没有购买任何域名。

标签: php apache amazon-ec2 centos


【解决方案1】:

您需要为对应的虚拟主机条目设置ServerNameServerAlias(域名而不是ip)以及正确的DocumentRoot

ServerAlias 是可选的。

ServerName : xyz.com
ServerAlias  : www.xyz.com

详细解释请参考blog post

【讨论】:

  • 我想 DocumentRoot 设置正确,但我还没有任何域名。如果我提供任何临时域名并将条目添加到 /etc/hosts 文件中,它仍然有效吗?
  • @RiddhishOjha 是的,它会:)。这就是在设置域之前测试配置的方法。
  • 谢谢@SojanVJose,我会测试它并告诉你。
猜你喜欢
  • 2017-09-22
  • 2013-07-07
  • 2019-09-02
  • 1970-01-01
  • 2017-03-15
  • 2012-05-10
  • 1970-01-01
  • 1970-01-01
  • 2013-10-15
相关资源
最近更新 更多