ddlddx0000 发表于 2018-11-20 08:05:11

apache编译安装方法及配置

  

  一、实验安装环境
  系统:CentOS6.6-i686
  软件:httpd-2.2.31.tar.gz
  关闭防火墙:/etc/init.d/iptables stop   

  关闭selinux:setenforce0

  二、Apache简介及其安装

  1.Apache简介

Apache是web服务软件,提供http服务。

2.Apache的特点

简单、速度快、应用广泛,主要是应用于静态小文件。
apache结合php可以实现动态。

3.Apache下载及其编译安装
  

  yum -y install zlib zlib-devel
  

  wgethttp://mirrors.sohu.com/apache/httpd-2.2.31.tar.gz

tar xf httpd-2.2.31.tar.gz

cd httpd-2.2.31

./configure \
--prefix=/application/apache2.2.31 \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-modules=most \
--enable-so \
--with-mpm-worker \
--enable-rewrite

make && make install


启动Apache: /apalication/apache/bin/apachectl start   

检查是否启动:lsof   -i   :80
  

  报错解决方法:
# ../../bin/apachectl -t
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
  

  vi conf/httpd.conf 找servername 加上如下:

#ServerName www.example.com:80
ServerName 127.0.0.1:80
  完成上诉步骤后Apache安装成功。
  

  三、测试是否成功
  

  在浏览器中输入本系统环境的ip,看到 Itworks !即代表安装成功。。。

  

  四、apache主配置文件详解

# vi httpd.conf
ServerRoot "/application/apache2.2.31"
Listen 80---监听的端口

Userdaemon
Group daemon

DocumentRoot "/application/apache2.2.31/htdocs"---站点根目录
---权限控制/
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all---拒绝所有


    Options Indexes FollowSymLinks --
    AllowOverride None
    Order allow,deny
    Allow from all    ---允许所有

---指定访问首页配置文件。
    DirectoryIndex index.html


    Order allow,deny
    Deny from all
    Satisfy All

ErrorLog "logs/error_log"---错误日志
LogLevel warn

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i
\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
   
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent
}i\" %I %O" combinedio
   
    CustomLog "logs/access_log" common


    ScriptAlias /cgi-bin/ "/application/apache2.2.31/cgi-bin/"




    AllowOverride None
    Options None
    Order allow,deny
    Allow from all

DefaultType text/plain

    TypesConfig conf/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz


SSLRandomSeed startup builtin
SSLRandomSeed connect builtin




虚拟主部署机:
部署多个站点,每个站点希望用不同的域名和站点目录,或者不同的端口、不同的IP,则需要虚拟主机的功能。
一个http服务配置多个站点,就需要多个虚拟主机

虚拟主机的分类:
1.基于域名(本文主要讲解这个)
2.基于端口
3.基于IP

域名                                        站点目录
www.chen.com                      /var/html/www
bbs.chen.org                        /var/html/bbs
blog.chen.org                      /var/html/blog

1)创建站点目录
  

  mkdir -p   /var/html/{www,bbs,blog}
  

  2)向里面写入index.html
  

  for name in www blog bbs; do echo   "http://$name.chen.com">/var/html/$name/index.html; done
  

  # tree /var/html/
/var/html/
├── bbs
│   └── index.html
├── blog
│   └── index.html
└── www
    └── index.html

3 directories, 3 files
#

  

  3)查看里面内容信息
  

  for name in www blog bbs; docat   /var/html/$name/index.html; done
  

  4)打开Apache主配置文件把Include conf/extra/httpd-vhosts.conf前面的#号去掉
  

   # Virtual hosts
Include conf/extra/httpd-vhosts.conf


   5)打开/application/apache/conf/extra/httpd-vhosts.conf配置文件,做如下修改
  #www.chen.com vhosts

    ServerAdmin 1297212044@qq.com
    DocumentRoot "/var/html/www"
    ServerNamewww.chen.com
    ServerAliaschen.com
    ErrorLog "logs/www-error_log"
    CustomLog "logs/www-access_log" common



#bbs.chen.com vhosts

    ServerAdmin 1297212044@qq.com
    DocumentRoot "/var/html/bbs"
    ServerNamebbs.chen.com
    ErrorLog "logs/bbs-error_log"
    CustomLog "logs/bbs-access_log" common


#blog.chen.com vhosts

    ServerAdmin 1297212044@qq.com
    DocumentRoot "/var/html/blog/"
    ServerNameblog.chen.com
    ErrorLog "logs/blog-error_log"
    CustomLog "logs/blog-access_log" common


配置完成后检查语法和平滑重启:
  /application/apache/bin/apachectl   -t      

  /application/apache/bin/apachectl    graceful
  

  6)在windows中的hosts文件中做解析
  10.0.0.6 ww.chen.combbs.chen.com   blgo.chen.com   

  

  7)输入域名则即可实现访问。
  

  

  




页: [1]
查看完整版本: apache编译安装方法及配置