源码安装apache 虚拟主机
官方下载目前稳定版本,http://mirror.esocc.com/apache/httpd/httpd-2.2.27.tar.gz ,解压安装如下,安装apache之前,需要先安装apr apr-util。# tar zxvf httpd-2.2.27.tar.gz
# yum install -y apr apr-util apr-util-devel
# cd httpd-2.2.27
编译之前确定你的电脑已安装gcc
# ./configure --prefix=/usr/local/apache2 --enable-rewrite --enable-so
# make
# make install
然后启动apache服务:/usr/local/apache2/bin/apachectl start
提示:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName解决方案:将/usr/local/apache2/conf/httpd.conf面的#ServerName localhost:80注释去掉即可。
查看apache进程及端口:
# netstat -tnl |grep 80
tcp 0 0 :::80 :::*
# ps -ef |grep httpd
root 17295 10 13:14 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 17296 172950 13:14 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 17297 172950 13:14 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 17298 172950 13:14 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 17299 172950 13:14 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 17300 172950 13:14 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 17301 172950 13:14 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 17302 172950 13:14 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
daemon 17303 172950 13:14 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
root 1731667810 13:21 pts/0 00:00:00 grep httpd
源码包安装Apache默认发布目录为:/usr/local/apache2/htdocs/下。
启动apache服务:# /usr/local/apache2/bin/apachectl start
二、Apache基于域名虚拟主机配置,这个就叫做虚拟主机,在一台机器可以搭建多个网站。
修改vi /usr/local/apache2/conf/extra/httpd-vhosts.conf虚拟主机配置文件内容如下:
NameVirtualHost *:80
ServerAdmin webmaster@antpedia.com 管理员邮箱
DocumentRoot /www/wwwroot/supesite DocumentRoot 指的是网站文件存放的目录 ServerName www.ruizengguiji.com 是网站的域名
DirectoryIndex index.htm index.html home.php index.php index.cgi
DefaultLanguage zh-CN
AddDefaultCharset UTF-8
ErrorDocument 404 /error/err.html
Options FollowSymLinks
AllowOverride All
Order deny,allow
第二个虚拟主机:
ServerAdmin webmaster@antpedia.com
DocumentRoot /www/wwwroot/supesite2
ServerName david.ruizengguoji.com
DirectoryIndex index.htm index.html home.php index.php index.cgi
DefaultLanguage zh-CN
AddDefaultCharset UTF-8
ErrorDocument 404 /error/err.html
Options FollowSymLinks
AllowOverride All
Order deny,allow
把httpd.conf中Include conf/extra/httpd-vhosts.conf取消注释
保存退出!重启apache服务 新建文件 mkdir /data/webapps/www1 www2
进入到相应的目录下创建index.html
echo wgk1 www.wugk.com >>index.html
echo wgk2 www.wugk.com >>index.html
测试检查文件有没有错误:/usr/local/apache2/bin/apachectl -t
重新加载apache不中断apache:/usr/local/apache2/bin/apachectl graceful
在测试机上配置 运行:c:\WINDOWS\system32\drivers\etc
打开hosts增加内容:192.168.1.7(提供apache服务地址)www.wugk1.com(指定域名1) www.wugk2.com(指定域名2) www.wugk3.comwww.wugk4.com www.wugk5.com
页:
[1]