美文网首页
Mac Apache 配置虚拟主机

Mac Apache 配置虚拟主机

作者: lenbolan | 来源:发表于2020-10-23 15:16 被阅读0次
  1. 在 /private/etc/apache2/ 目录下找到 httpd.conf 并打开
    找到:
# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf

去掉 Include 前的 # 号

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

可以把 /private/etc/apache2/extra/ 下的 httpd-vhosts.conf
复制到自己的目录下以方便修改,并修改配置

# Virtual hosts
Include /Users/yourname/Sites/httpd-vhosts.conf
  1. 在 httpd-vhosts.conf 中添加站点配置
<VirtualHost *:80>
    ServerAdmin webmaster@test.com
    DocumentRoot "/Users/yourname/Sites/www.test.com"
    ServerName www.test.com
    <Directory "/Users/yourname/Sites/www.test.com">
        Options Indexes FollowSymLinks
        AllowOverride All

        Require all granted
    </Directory>
    ErrorLog "/Users/yourname/Sites/www.test.com/tests.com-error_log"
    CustomLog "/Users/yourname/Sites/www.test.com/test.com-access_log" common
</VirtualHost>
  1. 重启 apachectl 服务
sudo apachectl restart

即可

如需配置 url rewrite(地址重写)

  1. 打开 /private/etc/apache2/httpd.conf 找到
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so

去掉前面的 # 号

LoadModule rewrite_module libexec/apache2/mod_rewrite.so
  1. 在虚拟主机配置文件 httpd-vhosts.conf 中
<Directory "/Users/yourname/Sites/www.test.com">
        Options Indexes FollowSymLinks
        AllowOverride All

        Require all granted
    </Directory>

AllowOverride None 要改为 AllowOverride All

  1. 在站点目录下添加 .htaccess 文件
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteCond
RewriteRule address1.php address2.php
</IfModule>

根据地址重写规则编写 RewriteCond RewriteRule

相关文章

网友评论

      本文标题:Mac Apache 配置虚拟主机

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