PHP配置虚拟域名 Vhost

本文详细介绍了如何使用PHP配置Apache虚拟主机。首先,需要在httpd.conf中加载rewrite_module并重启Apache。接着,开启Include httpd-vhosts.conf,并在vhosts.conf文件中设置虚拟主机信息。然后,在特定目录下配置域名、DocumentRoot、权限等。最后,通过Apache的重启和mod_rewrite规则,实现URL重写和虚拟目录功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一..用PHP方法配置虚拟域名:

1.apache配置文件/usr/local/apache/conf/httpd.conf中打开
 LoadModule rewrite_modulemodules/mod_rewrite.so

2.重启apache  /usr/local/apache/bin/apachectl restart

3.通过phpinfo查看LoadModule 确实打开:


4. conf/httpd.conf中开启Include conf/extra/httpd-vhosts.conf

    然后到: conf/extra/httpd-vhosts.conf

<VirtualHost118.178.191.37:80>

    ServerAdminwebmaster@dummy-host.example.com

    DocumentRoot"/data/wwwroot/default/wisedata"

    ServerName www.wisedata.cc

    ServerAlias www.dummy-host.example.com

    ErrorLog"logs/dummy-host.example.com-error_log"

    CustomLog"logs/dummy-host.example.com-access_log" common

</VirtualHost>

    然后找到/usr/local/apache/conf/vhost/wisedata.cc.conf文件增加相关域名

<VirtualHost*:80>

    ServerAdmin admin@linuxeye.com

    DocumentRoot"/data/wwwroot/default/wisedata"

    ServerName www.wisedata.cc

    ErrorLog"/data/wwwlogs/wisedata.cc_error_apache.log"

    CustomLog"/data/wwwlogs/wisedata.cc_apache.log" common

<Directory"/data/wwwroot/default/wisedata">

    SetOutputFilter DEFLATE

    Options FollowSymLinks ExecCGI

    Require all granted

    AllowOverride All

    Order allow,deny

    Allow from all

    DirectoryIndex index.html index.php

</Directory>

</VirtualHost>

5. .重启apache /usr/local/apache/bin/apachectl restart

 

6. /usr/local/apache/conf/extra路径下


其他

RewriteRule ^/index([0-9]*)/$ /index.php?id=$1 [R]   //虚拟目录 

mod_rewrite 规则修正符 
1) R 强制外部重定向 
2) F 禁用URL,返回403HTTP状态码。 
3) G 强制URL为GONE,返回410HTTP状态码。 
4) P 强制使用代理转发。 
5) L 表明当前规则是最后一条规则,停止分析以后规则的重写。 
6) N 重新从第一条规则开始运行重写过程。 
7) C 与下一条规则关联 
如果规则匹配则正常处理,以下修正符无效 
8) T=MIME-type(force MIME type) 强制MIME类型 
9) NS  只用于不是内部子请求 
10) NC 不区分大小写 
11) QSA 追加请求字符串 
12) NE 不在输出转义特殊字符   \%3d$1  等价于 =$1 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值