Configure Apache Virtual Hosts o
2016-09-01 本文已影响0人
NicolasWan
- Open the terminal app and switch to the
rootuser 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
UserandGroup:
User _www
Group _www
- Rewrite them, here
Useruses 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 keyat the very first place of each line. - Add the following block:
DocumentRootis the directory where you want to serve your files,ServerNameis the name of this virtual host,Proxyis 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://mysitein your browser, start browsing your files in theDocumentRootdirectory. - Don't know how to play vi editor? Try
command + shift + Gin finder to locate configuration files.