尊旭网
当前位置: 尊旭网 > 知识 >

apache 虚拟主机,如何配置 Apache 的虚拟主机

时间:2024-05-27 08:44:18 编辑:阿旭

1,如何配置 Apache 的虚拟主机

打开httpd.conf文件
去掉LoadModule vhost_alias_module modules/mod_vhost_alias.so
这句前面的#号

Include conf/extra/httpd-vhosts.conf这句前面的#号

Include conf/extra/httpd-vhosts.conf这句在httpd.conf文件底部

然后打开Apache2.2\conf\extra下的httpd-vhosts.conf文件,加入如下代码

#配置自己的虚拟主机

#网站目录,如果在www目录下的php目录,下面 #就填写F:/www/php
DocumentRoot "D:/WALP/www"
#域名
ServerName www.plqjnet.com
#这里配置欢迎首页面
DirectoryIndex index.html index.htm index.php

Options FollowSymLinks
#不允许别人修改我们的页面
AllowOverride None
#设置访问权限
order allow,deny
Allow from all



把ServerName改成你自己的,最后重启Apache。

2,如何配置 Apache 的虚拟主机

Apache 的虚拟主机就是在一台服务器上运行多个网站,每个虚拟主机都可以绑定独立的域名,为这些域名可以指定单独的目录,访问这些域名的时候,Apache 会打开对应目录里面的东西。配置 Apache 的虚拟主机,只需要去修改 Apache 的配置文件。虚拟主机的英文是 virtual host,所以,Apache 配置虚拟主机的文件可能是 httpd.conf ,也可能是跟 virtual host 这个名字相关的文件,比如 vhost.conf ,具体要使用哪一个配置文件,需要自己去判断。

3,如何配置 Apache 的虚拟主机

方法/步骤
Apache配置虚拟主机方法在windows和linux有些差异,今天给大家演示如何在windows上配置Apache虚拟主机,此方法主要适用于独立的Apache环境。
1. 打开目录Apache的安装目录/conf/extra/, 找到 httpd-vhosts.conf 文件;

2. 添加一段代码来指定某一域名的网站,如图我配置虚拟域名是:
project.com,文件目录指向的是CI框架;


ServerAdmin [email protected]
DocumentRoot "D:/AMP/Apache/htdocs/ci"
ServerName project.com
ErrorLog "logs/project.com-error.log"
CustomLog "logs/project.com-access.log" common


3. 打开 httpd.conf 文件, 添加如下代码:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

如果已存在,将Include前面的#去掉;

4. 重启 Apache 服务,打开虚拟域名之后,结果如图所示:

4,如何配置 Apache 的虚拟主机

怎样配置Apache虚拟主机


分步阅读
怎样利用Apache在一台Linux服务器上面运行多个网站,最简单快速的方法。
工具/原料
一台Linux服务器
方法/步骤
安装Apache软件包
yum -y install httpd
(这里只实现Apache的虚拟主机功能,LAMP架构还需要安装php和mysqld-server等软件包)

打开Apache的主配置文件
#vim /etc/httpd/conf/httpd.conf
取消“#NameVirtualHost *:8”行首#注释
NameVirtualHost *:8
添加

ServerAdmin [email protected]
DocumentRoot /var/www/html/web1
ServerName web1.example.com
ErrorLog logs/web1.example.com-error_log
CustomLog logs/web1.example.com-access_log common





ServerAdmin [email protected]
DocumentRoot /var/www/html/web2
ServerName web2.example.com
ErrorLog logs/web2.example.com-error_log
CustomLog logs/web2.example.com-access_log common


ServerAdmin是网站管理员的邮箱
DocumentRoot是网站存放的路径
ServerName是你的网站域名
ErrorLog、CustomLog是日志文件
添加多个网站的时候DocumentRoot和ServerName必须不同


启动Apache服务
/etc/init.d/httpd start
chkconfig httpd on
在防火墙中添加80端口
#grep 80 /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

5
在域名管理后台添加域名解析记录,然后访问域名就能跳转到对应的网站上面了。

注意事项
虚拟主机的DocumentRoot参数不能和Apache的默认站点目录相同