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

 时间:2026-02-17 05:19:41

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

sudo nano /etc/hosts

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

配置如下:

127.0.0.1  yii2  

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

保存即可

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

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

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

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

然后保存

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

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

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

<Directory "/srv/http/">          Options Indexes FollowSymLinks Includes ExecCGI    AllowOverride All    Require all granted</Directory>

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

然后在下面增加:

<VirtualHost *:80>    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</VirtualHost>

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

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

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

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

  • 怎样配置Apache虚拟主机
  • apache配置虚拟主机
  • Apache配置虚拟主机
  • 如何配置 Apache 的虚拟主机
  • 如何在Windows系统中配置Apache虚拟主机
  • 热门搜索
    tweet是什么意思 什么是熟语 戌的意思 led灯什么牌子好 pron是什么意思 槿的意思 与人为善的意思 现在什么电视剧最火 甲子是什么意思 lesson是什么意思