您的位置首页百科问答

apache2.4以上版本配置虚拟主机

apache2.4以上版本配置虚拟主机

的有关信息介绍如下:

apache2.4以上版本配置虚拟主机

linux Apache-2.4基于域名访问的多虚拟主机配置

在linux下使用任意编辑器比如vim或者nano等命令行编辑即可,输入以下命令:

sudo nano /etc/hosts

修改hosts,将需要添加的域名和127.0.0.1绑定

配置如下:

127.0.0.1 yii2

我使用的是yii2这个域名,可以是yii.web 或者其它

保存即可

配置/etc/httpd/conf/httpd.conf (由于操作系统不同可能会有不同的路径,此处使用的是archlinux桌面环境)

去掉vittual hosts 下面的 Include conf/extra/httpd-vhosts.conf 前面的注释

在httpd.conf里搜索AllowOverride 将后面的参数更改为All即可

然后保存

修改 /etc/httpd/conf/extra/httpd-vhosts.conf

增加下面内容 ,2.4以后这部分内容很重要

Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Require all granted

/srv/http/是根目录,视情况而定,在ubuntu或者fedora以及cent os 里可能是/var/www/

然后在下面增加:

ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "/srv/http/yii2/web" ServerName yii2 ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log" CustomLog "/var/log/httpd/dummy-host2.example.com-access_log" common

ServerName 以及DocumentRoot这一部分一定要写对!其它可以默认即可!

重启apache,在archlinux里的命令是systemctl restart httpd.service ubuntu及其它发行版百度搜索一下!

在浏览器地址栏输入http://yii2 打开,如跳转到你的网站主页面,说明配置成功