【问题标题】:How to configure apache for multiple websites e.g. <my_website_name>.localhost如何为多个网站配置 apache,例如<我的网站名称>.localhost
【发布时间】:2015-04-15 11:07:37
【问题描述】:

我想在我的本地计算机上设置多个网站。我希望本地网络上的所有其他计算机都能够访问这些。

所以我想映射不同的项目/www/html/&lt;proj_web_root&gt;

&lt;proj_name&gt;.localhost,以便所有其他计算机都可以访问这些网站

&lt;proj_name&gt;.my_ip 和我在本地喜欢 &lt;proj_name&gt;.localhost

如何在/etc/apache2/sites-enabled 文件和/etc/hosts 中为每个网站配置此功能

【问题讨论】:

    标签: apache ubuntu


    【解决方案1】:

    就个人而言,我会避免使用 .local 域作为共享组域。使用 .dev 之类的东西

    在 Apache 中,您可以在 VirtualHost 中使用 ServerName 和 ServerAlias 指令并重写规则以实现 URL 路由,例如

    <VirtualHost *:80>
    ServerName www.dev
    ServerAlias sub.dev
    DocumentRoot /www/html
    
    RewriteRule ^(.*) %{HTTP_HOST}/$1
    </VirtualHost>
    

    您显然也可以使用通配符别名。在 /etc/apache/sites-available 中另存为 dev.conf。激活工作:

    a2enmod rewrite
    a2ensite dev
    

    我一般不赞成主机黑客,但如果你坚持,这只是向 /etc/hosts 添加东西的情况

    这种方法的一个问题是您不能在主机名上使用通配符。我建议您使用 dnsmasq 之类的东西,因为您可以添加通配符条目。在您的 /etc/dnsmasq.conf 中,您可以添加类似的内容(相应地更改 IP 地址):

    address=/.dev/10.0.0.2
    

    在所有情况下,查看您的 /etc/resolv.conf 以了解您的 dns 解析的优先级

    【讨论】:

      猜你喜欢
      • 2016-10-13
      • 1970-01-01
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      • 2015-01-13
      • 2012-10-03
      • 1970-01-01
      • 2020-07-14
      相关资源
      最近更新 更多