Configure Apache Virtual Hosts on Mac OS X

  • Open the terminal app and switch to the root user to avoid permission issues while configuring:
sudo su
  • Edit the Apache configuration file:
vi /etc/apache2/httpd.conf
  • Find the following line:
#Include /private/etc/apache2/extra/httpd-vhosts.conf
  • Remove the pound key, as the following line:
Include /private/etc/apache2/extra/httpd-vhosts.conf
  • Find the User and Group:
User _www
Group _www
  • Rewrite them, here User uses your own user:
User $(whoami)
Group wheel
  • Find the following block:
<Directory />
    AllowOverride none
    Require all denied
</Directory>
  • Rewrite as below:
<Directory />
    AllowOverride all
    Require all granted
</Directory>
  • Save this file.
  • Setup up virtual hosts:
vi /etc/apache2/extra/httpd-vhosts.conf
  • Annotate example hosts by adding the pound key at the very first place of each line.
  • Add the following block: DocumentRoot is the directory where you want to serve your files, ServerName is the name of this virtual host, Proxy is used for configuring reverse proxy.
<VirtualHost *:80>
    DocumentRoot "/Users/$(whoami)/Documents/WorkSpace"
    ServerName mysite
    ErrorLog "/private/var/log/apache2/mysites-error_log"
    CustomLog "/private/var/log/apache2/mysites-access_log" common
    <Directory "/Users/$(whoami)/Documents/WorkSpace">
        Options FollowSymLinks Multiviews Indexes 
        MultiviewsMatch Any
        AllowOverride None
        Require all granted
    </Directory>
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPass /web $(your server url)/web
    ProxyPassReverse /web $(your server url)/web
</VirtualHost>
  • Save this file.
  • Map virtual hosts:
vi /etc/hosts
  • Add the following line:
127.0.0.1 mysite
  • Save this file.
  • Start or restart Apache:
    • If first time run Apache:
    apachectl start
    
    • Not first time:
    apachectl restart
    
  • Type http://mysite in your browser, start browsing your files in the DocumentRoot directory.
  • Don't know how to play vi editor? Try command + shift + G in finder to locate configuration files.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Mac系统自带apache服务器 查看apache版本sudo apachectl -v 启动apachesudo...
    慢飞鸟阅读 21,652评论 3 16
  • 我的Mac OS X 版本是10.11.6。 启动Apache 打开“终端(terminal)”,输入 sudo ...
    Show_Perry阅读 1,788评论 1 3
  • 我们经常性的需要使用局域网搭建 Web 服务器测试环境,如部署局域网无线安装企业应用等,Mac OS X 自带了 ...
    小白不是总阅读 55,522评论 24 134
  • 一、概述 二、编译安装 三、httpd服务基础 四、httpd.conf配置文件 五、httpd服务访问控制 六、...
    紫_轩阅读 992评论 0 0
  • 脚印重重叠叠 新与旧的 绿蔓绕过扭曲的紧闭的铁门 爬满窗台 插一朵爱人送来的花 其他的…… 就从红指甲偷偷长出来 ...
    讲个笑话不准哭阅读 170评论 2 2