Apache 如何为本地开发设置虚拟主机

Apache 如何为本地开发设置虚拟主机,apache,vhosts,Apache,Vhosts,当我在地址栏example.local中写入时,如何设置Apache 2.2以从htdocs/example/加载站点 提前感谢您必须确保example.local解析到您的本地计算机,最简单的方法是添加一行,如 127.0.0.1 example.local 到您的主机文件(linux:/etc/hosts;win:%SystemRoot%\system32\drivers\etc\hosts)。 然后在apache配置中需要vhost,比如(这是非常基本) ServerName exa

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


提前感谢

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

127.0.0.1  example.local
到您的主机文件(linux:/etc/hosts;win:%SystemRoot%\system32\drivers\etc\hosts)。 然后在apache配置中需要vhost,比如(这是非常基本)


ServerName example.local
DocumentRoot/path/to/htdocs
ErrorLog/path/to/error.log
CustomLog/path/to/access.log组合
这样,您应该能够访问htdocs/example/via中的文件


有关更多详细信息,请参阅

如果我要添加多个网站,例如1.local、example2.local等,该怎么办?
<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>