果果、 发表于 2018-11-19 13:10:52

Apache web服务器的相关知识整理及简要说明

      本文将梳理Apache    web网站服务器的相关知识,以及在CentOS6.7环境中简单配置Apache web网站的相关用法!
  
  一. Apache web程序安装
        利用光盘,制作本地RPM镜像源,利用yum安装httpd程序包。
      (1)挂载本地光盘
# mount /dev/sr0 /media/cdrom
mount: block device /dev/sr0iswrite-protected, mounting read-only
#  

      (2)查看httpd程序包
#yum list | grep httpd*
httpd.x86_64                           2.2.15-53.el6.centos      base   
httpd-devel.i686                         2.2.15-53.el6.centos      base   
httpd-devel.x86_64                        2.2.15-53.el6.centos         base
httpd-manual.noarch                      2.2.15-53.el6.centos      base   
httpd-tools.x86_64                     2.2.15-53.el6.centos          base
#  

  说明:各RPM软件包的用途如下:
  httpd: 是Apache服务器的程序软件包,包含服务器的执行程序、配置文件、启动脚本等必备的文件
  httpd-devel: 是Apache HTTP服务器的开发工具包
  httpd-mannual: 是Apache 服务器的帮助手册文档,以网页的形式提供了Apache服务器的完整说明文档。
  httpd-tools : 是 Apache HTTP服务器的工具包。
  
  (3)yum安装Apachehttpd程序包,利用yum安装,可以充分解决程序包之间的依赖关系,简单易用
# yum -y install httpd
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.neusoft.edu.cn
* extras: mirrors.neusoft.edu.cn
*updates:mirrors.neusoft.edu.cnResolving Dependencies
--> Running transaction check
---> Packagehttpd.x86_640:2.2.15-53.el6.centos will be installed
......                                                   
Installed: httpd.x86_640:2.2.15-53.el6.centos                                                                        
Dependency Installed:
apr.x86_64 0:1.3.9-5.el6_2                           
apr-util.x86_640:1.3.9-3.el6_0.1                        
apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1               
httpd-tools.x86_640:2.2.15-53.el6.centos            
Complete!
#  

     (4)查看httpd包安装完成后,生成哪些文件
# rpm -ql httpd
/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf.d/README
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/httpd/logs
/etc/httpd/modules
/etc/httpd/run
/etc/logrotate.d/httpd
/etc/rc.d/init.d/htcacheclean
/etc/rc.d/init.d/httpd
/etc/sysconfig/htcacheclean
/etc/sysconfig/httpd
/usr/lib64/httpd
/usr/lib64/httpd/modules
/usr/lib64/httpd/modules/mod_actions.so
......
/usr/lib64/httpd/modules/mod_vhost_alias.so
/usr/sbin/apachectl
/usr/sbin/htcacheclean
/usr/sbin/httpd
......
/usr/sbin/suexec/usr/share/doc/httpd-2.2.15
......
/usr/share/doc/httpd-2.2.15/VERSIONING
/usr/share/man/man8/apachectl.8.gz
......
/usr/share/man/man8/suexec.8.gz
/var/cache/mod_proxy
/var/lib/dav
/var/log/httpd
/var/run/httpd
/var/www
/var/www/cgi-bin
/var/www/error
/var/www/error/HTTP_BAD_GATEWAY.html.var
......
/var/www/error/noindex.html
/var/www/html
var/www/icons
var/www/icons/README
/var/www/icons/README.html
/var/www/icons/a.gif
......
/var/www/icons/world1.gif
/var/www/icons/world1.png
/var/www/icons/world2.gif
/var/www/icons/world2.png
#  

     说明:
/etc/httpd                ------->配置文件的目录
/etc/rc.d/init.d/         ------->httpd服务启动脚本目录
/usr/lib64/httpd/modules------->httpd服务所用模块的目录
/var/www                  ------->web服务器网站所有文件的根目录
/var/www/error            ------->web服务器的错误相关处理的文件
/var/www/html             ------->web服务器静态网页的根目录
/var/www/icons            ------->web服务器网页所调用的图片的目录  

  二.   httpd的主要配置文件/etc/httpd/conf/httpd.conf的简要说明:
                  /etc/httpd/conf/httpd.conf文件是http服务的主配置文件,其中包含的配置项直接决定着web服务器的各项运行参数及服务器性能,其内容主要包括以下三个部分:
Section 1: Global Environment                     ------> 全局环境配置部分
Section 2: 'Main' server configuration            ------>主服务配置部分
Section 3: Virtual Hosts                        ------> 虚拟主机配置部分                  httpd.conf 文件由注释行和设置行两部分组成。
                 注释行以"#"开始,包含了对配置项进行说明和解释的内容,可以通过阅读注释行的内容,快速获得相关配置项的帮助信息。
                  设置行不以"#"开始,是配置文件中真正有效的设置内容。      
      常用设置项:
      (1)ServerRoot指令
                       设置Apache软件的配置文件的主目录。
                        语法格式:ServerRoot    directory-path
                        默认:"/etc/httpd"
      (2)Listen 指令:
                       设置服务器监听的IP以及端口号,默认监听服务器本机所有的IP地址的TCP 80端口。
                       语法格式:Listen    portnumber
                       默认:Listen 80
                  当然你可以配置多个选项,来监控更多的端口:
  示例:   Listen 80   
                    Listen 443
      (3)LoadModule 指令
      用来设置加载模块的指令,Apache的功能大部分由模块提供,并且支持动态装载和卸载模块(DSO), 模块文件一般位于SystemRoot根目录下的modules的目录里面
                 语法格式:LoadModule    module    filename
  示例:
LoadModuleauth_basic_modulemodules/mod_auth_basic.so
LoadModule auth_digest_modulemodules/mod_auth_digest.so
LoadModuleauthn_file_modulemodules/mod_authn_file.so      (4)Include 指令
                 用来设置从哪个目录中加载除主配置文件外的其他配置文件
                  语法格式:Include    file-path|directory-path
                 默认:Includeconf.d/*.conf   相对SystemRoot根目录。绝对路径是:/etc/httpd/conf.d/*.conf
                 示例:
Include /usr/local/apache2/conf/ssl.conf
Include/usr/local/apache2/conf/vhosts/*.conf     (5)User 指令和 Group 指令
                  用来设置启动httpd进程的用户及组名称
     (6)ServerAdmin 指令
                  通常来说当网站出现故障时,需要为客户提供一个可以帮助解决问题的邮件地址。例如管理网站的管理员地址。这条指令就是这种作用!
         语法格式:ServerAdmin    email-address|URL
         示例:ServerAdmin www-admin@foo.example.com   
      (7)ServerName 指令
                  用来标识服务器本身的主机名和端口,这条指令常用于配合主服务配置和虚拟主机配置。   
                  语法格式:ServerName    fully-qualified-domain-name[:port]
                       示例:ServerName    www.ipsecx.com
      (8)DocumentRoot指令
                 用来设置客户端访问网站的根路径,如果修改,请关闭Selinux服务。
                  语法格式:DocumentRoot    directory-path
                 默认:DocumentRoot"/var/www/html"   
      (9)DirectoryIndex指令
                  用来设置客户端请求网站时,要查找的网页列表
                  语法格式:DirectoryIndex local-url ...
                  默认:DirectoryIndexindex.htmlindex.html.var
      (10)AllowOverride指令
                    httpd允许在网页文档的各目录下使用.htaccess文件实现单目录资源的访问控制;表示哪此指令可以存放于.htaccess文件中。建议
                    语法格式:AllowOverride All|None|directive-type ...
                    开启此项,会大量占用服务器资源,建议AllowOverride的值设置为 None
      (11)Options指令
                  对指定的目录设置选项。
                       常用Options:
                       Indexes    Includes    FollowSymLinks    SymLinksifOwnerMatch    ExecCGI    MultiViews    None    All
                          None : 全部不允许
                          Indexes:允许索引,即当客户端无法找到请求的首页时,会列出当前目录的所有文件索引。
                          FollowSymLinks:允许跟踪符号链接;
                          SymLinksifOwnerMatch:如果匹配文件属主,允许跟踪符号链接
                          ExecCGI:允许执行CGI脚本;
                                 ...
                    语法格式:Options[+|-]option[[+|-]option] ...
  示例:

Options FollowSymLinks
AllowOverride None
      (12)order 指令
                             用来控制默认访问状态以及Allow与Deny的次序,如果使用Orderdeny,allow,则先会检查拒绝,在检查允许,当拒绝与允许有冲突时,允许优先,默认规则是允许。如果使用Order allow,deny则先检查允许,在检查拒绝,当允许与拒绝有冲突时,拒绝优先,默认规则是拒绝。
                 语法格式:Order    ordering
                 默认:Order Deny,Allow
                  注意:在http-2.2的版本中,对用户的访问控制,默认是全部允许;在httpd-2.4的版本中,默认是全部禁止
      (13)ErrorLog 指令
         语法格式:ErrorLogfile-path|syslog[:facility]
                    用来设置错误日志的存放位置,默认:ErrorLoglogs/error_log      
      (14)ErrorLogFormat指令:
                 设置错误日志的格式,可以参考Apache的帮助文档
      (15)CustomLog指令:
                 设置客户端的访问日志文件名以及日志格式,默认为 logs/access_log
                    语法格式:CustomLog    file|pipeformat|nicknameenvironment-variable]
         示例:
# CustomLog with format nickname
   LogFormat "%h %l %u %t \"%r\" %>s %b" common
   CustomLog logs/access_log common      (16)LogFormat指令
           该指令描述用户日志文件格式,可以直接使用Apache预先设置的格式字串,并且在配置的时候,我们会为LogFormat指令设置的日志格式创建别名,可以通过CustomLog指令调用该日志格式别名!
                 语法格式:LogFormat    format|nickname
                 默认:LogFormat "%h%l %u %t \"%r\" %>s %b"
                 示例:LogFormat "%v%h %l %u %t \"%r\" %>s %b" vhost_common
      (17)Alias指令
        用来设置目录别名,举例来说,当你在浏览器通过某个路径来访问某个图片时,实际上,web服务器内部已经将你输入的路径,切换到其他路径了。
                  语法格式:Alias    URL-path    file-path|directory-path
                  示例:
      Alias/images/"/webdata/pictures/"
    http://www.ipsecx.com/images/logo.jpg设置监听虚拟主机的IP和端口
       ServerName www.ipsecx.com             ----->设置主机域名地址
       DocumentRoot /data/vhosts/ipsecx      ----->设置网站资源的根目录
        

        虚拟主机2

      
       ServerName www.heihei.com
       DocumentRoot /data/vhosts/heihei
        

        
   由于作者水平有限,本文错漏缺点在所难免,希望读者批评指正。谢谢!
  




页: [1]
查看完整版本: Apache web服务器的相关知识整理及简要说明