时间:2023-07-14 07:21:01 | 来源:网站运营
时间:2023-07-14 07:21:01 来源:网站运营
Apache 在同一个IP上配置多台虚拟主机(多站点),监听多个端口:一键安装PHPStudy后,启动Apache,即可通过 http://127.0.0.1/ 访问默认配置的站点。DocumentRoot "D:/phpstudy_pro/WWW"
如果我们需要在同一个 IP(127.0.0.1)上放置多个站点(可以均为80端口或不同端口),则需要启用VHOST(虚拟主机)功能来实现:# 加载外部 conf/vhosts/vhosts.conf 配置文件Include conf/vhosts/vhosts.conf#同时监听 80 和 8080 端口Listen 127.0.0.1:80Listen 127.0.0.1:8080#加载 vhost_alias_module 模块LoadModule vhost_alias_module modules/mod_vhost_alias.so# 定义 SRVROOT 变量Define SRVROOT "D:/phpstudy_pro/Extensions/Apache2.4.39"#以上内容均可在 httd.conf 文件内搜索相关关键词,在对应位置删掉 '#' 注释符号或添加相应的行实现
2、配置 D:/phpstudy_pro/Extensions/Apache2.4.39/conf/vhosts/vhosts.conf :<VirtualHost 127.0.0.1:80> ServerName default DocumentRoot "${SRVROOT}/htdocs" FcgidInitialEnv PHPRC "D:/phpstudy_pro/Extensions/php/php7.3.4nts" AddHandler fcgid-script .php FcgidWrapper "D:/phpstudy_pro/Extensions/php/php7.3.4nts/php-cgi.exe" .php <Directory "${SRVROOT}/htdocs"> AllowOverride All Order allow,deny Allow from all Require all granted DirectoryIndex index.php index.html </Directory></VirtualHost><VirtualHost 127.0.0.1:80> ServerName www.example.com ServerAlias www.example.com DocumentRoot "${SRVROOT}/htdocs/example" <Directory "${SRVROOT}/htdocs/example"> AllowOverride All Order allow,deny Allow from all Require all granted DirectoryIndex index.php index.html </Directory></VirtualHost><VirtualHost 127.0.0.1:8080> ServerName example02.com ServerAlias www.example02.com DocumentRoot "${SRVROOT}/htdocs/example02" <Directory "${SRVROOT}/htdocs/example02"> AllowOverride All Order allow,deny Allow from all Require all granted DirectoryIndex index.php index.html </Directory></VirtualHost>
3、设置本机 C:/Windows/System32/drivers/etc/hosts 文件:# 添加如下两行127.0.0.1 www.example.com127.0.0.1 www.example02.com
如果两个虚拟主机需要共用 80 端口,则需要像上面一样,修改 Hosts 文件,通过在地址栏输入不同的域名访问不同的站点:FcgidInitialEnv PHPRC "D:/phpstudy_pro/Extensions/php/php7.3.4nts"AddHandler fcgid-script .phpFcgidWrapper "D:/phpstudy_pro/Extensions/php/php7.3.4nts/php-cgi.exe" .php
否则虚拟主机目录下的PHP文件会以源文件(纯文本)形式返回。关键词:主机,同一,配置,虚拟