luisedware / Archives

My Archives
45 stars 11 forks source link

Apache 配置 httpd-vhosts 虚拟主机 #3

Open luisedware opened 7 years ago

luisedware commented 7 years ago

步骤

开启Apache的mod_rewrite功能模块

//打开文件httpd.conf,
sudo vim /etc/apache2/httpd.conf

//找到mod_rewrite.so,删除#,开启路由 rewrite 功能、虚拟机模块
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so

引入http-vhosts.conf文件

//打开文件 httpd.conf
sudo vim /etc/apache2/httpd.conf

//找到 # Virtual hosts 的引入文件,删除#
Include /private/etc/apache2/extra/httpd-vhosts.conf

添加VirtualHost配置

//打开 http-vhosts.conf 文件,添加虚拟主机配置
sudo vim /private/etc/apache2/extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerName coding.com
    ServerAdmin coding.com
    DocumentRoot "/Users/anneason/www/"
    ErrorLog "/private/var/log/apache2/coding.com-error_log"
    CustomLog "/private/var/log/apache2/coding.com-access_log" common
</VirtualHost>

修改hosts文件

//打开 hosts 文件
sudo vim /etc/hosts

127.0.0.1 coding.com

在浏览器打开"conding.com",返回本地项目,配置成功。