通过/ etc / hosts将localhost目录更改为域名

时间:2017-03-30 09:42:26

标签: dns localhost hosts

我想知道是否有人可以建议我如何将域指向我localhost中的目录而不是localhost的根目录?

例如在我的主机文件中:

127.0.0.1 www.domain.com

  • 此作品

127.0.0.1/directory/ www.domain.com

  • 这不起作用?但是去那个域时我需要查看的目录是什么?

或者是否有更好的方法在localhost中设置多个站点,因为我在自己的目录中设置每个站点?

任何帮助将不胜感激

由于

1 个答案:

答案 0 :(得分:0)

您需要使用虚拟主机:

<VirtualHost *:80>

  # Admin email, Server Name (domain name) and any aliases
  ServerAdmin webmaster@domain1.com
  ServerName  domain1.com
  ServerAlias www.domain1.com


  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html
  DocumentRoot /home/demo/public_html/domain1.com/public


  # Custom log file locations
  LogLevel warn
  ErrorLog /var/log/apache2/error-mydomainname.com.log
  CustomLog /var/log/apache2/access-mydomainname.com.log combined

</VirtualHost>