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

2025-04-28 08:08:18

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以后这部分内容很重要&造婷用痃lt;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以上版本配置虚拟主机
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
相关推荐
  • 阅读量:46
  • 阅读量:35
  • 阅读量:61
  • 阅读量:96
  • 阅读量:32
  • 猜你喜欢