Configure Apache Virtual Hosts o

作者: NicolasWan | 来源:发表于2016-09-01 21:20 被阅读0次
  • 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.

相关文章

网友评论

    本文标题:Configure Apache Virtual Hosts o

    本文链接:https://www.haomeiwen.com/subject/wuchettx.html