您的位置:首页 > 运维架构 > Apache

mac 部署 apache

2015-10-11 12:21 519 查看


创建个人站点目录

cd ~/

mkdir Sites


创建成功后再在 用户/[你的用户名]/Sites 目录下创建log目录index.html文件

请检查”/etc/apache2/users”目录下,是否有名为“maomao.conf”的配置文件(同样:maomao需换成你的mac用户名),如果没有,手动创建一个,内容参考下面:(Directory的maomao替换掉)

<Directory "/Users/maomao/Sites/">
Options FollowSymLinks Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>


sudo vi /etc/hosts 以管理员身份打开hosts文件,追加一行

127.0.0.1       www.maomao.com


启用虚拟主机

默认情况下,apache的虚拟主机功能是关闭的,在“/etc/apache2/httpd.conf”中找到下面这行:

#Include /private/etc/apache2/extra/httpd-vhosts.conf


将前面的#去掉,然后再打开“/etc/apache2/extra/httpd-vhosts.conf”,内容修改成类似下面的样子:(maomao改成你的mac用户名)

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot "/usr/docs/dummy-host.example.com"
#    ServerName dummy-host.example.com
#    ServerAlias www.dummy-host.example.com
#    ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
#    CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
#</VirtualHost>

#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host2.example.com
#    DocumentRoot "/usr/docs/dummy-host2.example.com"
#    ServerName dummy-host2.example.com
#    ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
#    CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
#</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
ErrorLog "/private/var/log/apache2/localhost-error_log"
CustomLog "/private/var/log/apache2/localhost-access_log" common
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/Users/maomao/Sites"
ServerName www.maomao.com
ErrorLog "/Users/maomao/Sites/log/error.log"
CustomLog "/Users/maomao/Sites/log/access.log" common
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>


修改private/ect/apache2/http.conf

(这一步很重要,否则会报权限错误)

<Directory />
AllowOverride none
#Require all denied
allow from All
</Directory>


启动服务器

udo apachectl start


访问www.maomao.com即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: