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:

    AllowOverride none
    Require all denied

  • Rewrite as below:

    AllowOverride all
    Require all granted

  • 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.

    DocumentRoot "/Users/$(whoami)/Documents/WorkSpace"
    ServerName mysite
    ErrorLog "/private/var/log/apache2/mysites-error_log"
    CustomLog "/private/var/log/apache2/mysites-access_log" common
    
        Options FollowSymLinks Multiviews Indexes 
        MultiviewsMatch Any
        AllowOverride None
        Require all granted
    
    
        Order deny,allow
        Allow from all
    
    ProxyPass /web $(your server url)/web
    ProxyPassReverse /web $(your server url)/web

  • 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.

你可能感兴趣的:(Configure Apache Virtual Hosts on Mac OS X)