http服务之Apache

当前互联网主流web服务

  静态服务:
    apache-->中小静态web服务主流,web服务器的老大哥。
    nginx-->大型新兴静态web服务主流,web服务器中的初生牛犊。
    lighttpd-->静态效率很高,不温不火
  动态服务:
    IIS-->微软的web服务。
    tomcat-->中小企业动态web服务,互联网java容器主流。
    resin-->大型动态web服务,互联网java容器主流。
    php(fcgi)-->php程序的解析容器
      1.配合apache,php不是守护进程,而是moudel(模块)
      2.配合nginx、lighttpd,php守护进程模式,FCGI模式

Apache介绍:

  Apache HTTP Server (简称Apache)是Apache软件基金会的-一个高性能、功能强大,健壮可靠、又很灵活的开放源代码的web服务软件,它可以运行在广泛使用的计算机平台上,如:unix,linux,windows。 因其多平台性和很好的安全性而被广泛使用,是当今互联网最流行的Web服务端软件之一。
Apache的特点:

  功能强大、配置简单、速度快、应用广泛、性能稳定可靠,并可做代理服务器或负载均衡来使用。
Apache的应用场合:

  使用Apache运行静态HTML网页、图片(处理静态小文件能力不及Nginx) 。
  使用Apache结合PHP引擎运行PHP、Perl等程序,LamP被称之为经典组合。
  使用Apache结合TomcatResin运行JSP,JAVA等程序,成为中小企业的首选。
  使用Apache作代理、负载均衡、rewrite规则过滤等等。
Apache的安装:环境是cen6 http-2.2.27
下载并解压安装包,注意要将安装包放在指定目录下

[root@localhost tools]# tar xf httpd-2.2.27.tar.gz 
[root@localhost tools]# cd httpd-2.2.27

安装参数详解:

./configure 
--prefix=/application/apache2.2. 27指定的安装目录
--enable-deflate 压缩客户请求的内容,速度快带宽小,但是消耗服务器CPU
--enable-expires 增加缓存
--enable-headers 激活http的头
--enable-modules=most 激活大多数模块
--enable-so 
--with-mpm=worker 启动多线程服务
--enable-rewrite激活伪静态功能

编译安装:

[root@localhost httpd-2.2.27]# ./configure --prefix=/application/apache2.2.27--enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite
[root@localhost httpd-2.2.27]# make
[root@localhost httpd-2.2.27]# make install

创建软连接:

[root@localhost httpd-2.2.27]# ln -s /application/apache2.2.27 /application/apache

当出现不能访问测试页面的时候:
  查看防火墙selinux的状态、查看对应的80端口的状态。

测试页面

Apache配置文件详解:

ServerRoot "/application/apache2.2.27"#服务的根目录
Listen 80#这个服务在那个端口监听
<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>
User daemon#用户
Group daemon#用户组
</IfModule>
</IfModule>
ServerAdmin you@example.com#管理员的邮箱
DocumentRoot "/application/apache2.2.27/htdocs"#默认的站点目录
<Directory />#表示根目录拒绝其他人访问
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/application/apache2.2.27/htdocs">#当新建站点时,需要增加以下的内容
Options Indexes FollowSymLinks#当没有首页时会显示根目录就跟Indexes有关,优化apache需要去掉这个参数
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<FilesMatch "^.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
LogFormat "%h %l %u %t "%r" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/application/apache2.2.27/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/application/apache2.2.27/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
DefaultType text/plain
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
</IfModule>
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

Apache扩展配置文件:
*httpd-vhosts.conf
当在一个服务器上配置多个域名或者多个网站时在下面增加如下内容:

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/application/apache2.2.27/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
*httpd-mpm.conf

  里边有两种模式及其相关的参数设置。
httpd-default.conf

原文地址:https://www.cnblogs.com/zrxuexi/p/11637849.html