【问题标题】:How to setup vhosts for local development如何为本地开发设置虚拟主机
【发布时间】:2011-07-29 20:48:44
【问题描述】:

当我在地址栏 example.local 中写入时,如何设置 Apache 2.2 从 htdocs/example/ 加载站点?

提前致谢

【问题讨论】:

    标签: apache vhosts


    【解决方案1】:

    你必须确保 example.local 解析到你的本地机器,最简单的方法是添加一行

    127.0.0.1  example.local
    

    到您的主机文件(linux:/etc/hosts;win:%SystemRoot%\system32\drivers\etc\hosts)。 而且你的 apache 配置中需要一个虚拟主机,比如(这是非常基本的)

    <VirtualHost 127.0.0.1:80>
      ServerName    example.local
      DocumentRoot  /path/to/htdocs
      ErrorLog      /path/to/error.log
      CustomLog     /path/to/access.log combined
    </VirtualHost>
    

    这样你应该可以通过http://example.local/example/访问htdocs/example/中的文件

    更多详情请参考fine apache manual

    【讨论】:

    • 如果我想添加多个网站,example1.local,example2.local 等怎么办?
    猜你喜欢
    • 2019-06-11
    • 2011-12-23
    • 1970-01-01
    • 2014-04-02
    • 2020-07-17
    • 2015-01-12
    • 2018-07-04
    • 1970-01-01
    • 2018-06-26
    相关资源
    最近更新 更多