在Mac OS X上设置虚拟主机(vhost)并优雅地重新启动Apache Web服务器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Mac OS X上设置虚拟主机(vhost)并优雅地重新启动Apache Web服务器相关的知识,希望对你有一定的参考价值。

A great way to work on website in Mac OS X is to set up a vhost. Doing so is very easy. In System Preferences click on Sharing and then make sure you have Personal Web Sharing turned on. Then, open or create your vhosts.conf file (/private/etc/httpd/users/vhosts.conf). Enter the VirtualHost information (see snippet below). The ServerName can be anything and the DocumentRoot should be the path to the folder where you want to build the website. Lastly, open the Terminal and enter the command below. It will restart Apache and will enable your new vhost.
  1. //This is the code that goes in the vhosts.conf file (/private/etc/httpd/users/vhosts.conf)
  2. //Substitute domain.web for domain you will use to access the vhost on your computer.
  3. //For example, if I was working on cnn.com, I would change domain.web to cnn.web. For the
  4. //document root I would change domain.com to cnn.com.
  5.  
  6. <VirtualHost *:80>
  7. ServerName domain.web
  8. DocumentRoot /Library/WebServer/Documents/domain.com/
  9. </VirtualHost>
  10.  
  11. //This is the command line to be used in Terminal.app to restart Apache gracefully.
  12.  
  13. sudo apachectl -k graceful

以上是关于在Mac OS X上设置虚拟主机(vhost)并优雅地重新启动Apache Web服务器的主要内容,如果未能解决你的问题,请参考以下文章

使用 AMPPS 在 mac (Mac OS X Lion 10.70.4) 上设置虚拟主机

如何让虚拟主机在 OS X Lion 中工作?

OS X 10.9 Mavericks - 使用虚拟主机设置本地主机

Xampp Mac OS 虚拟主机

MAC OS X:MAMP 环境和虚拟主机

OS X Mavericks 上支持 SSL 的虚拟主机