web服务器apache理论、实践详解

起始行<version>协议版本号 <status>状态码 <reason-phrase>原因短语

首部:<headers>可以有多个

请求的主体部分:<entity-body>

[root@stu2~]# telnet 172.16.0.1 80Trying172.16.0.1…Connectedto 172.16.0.1.Escapecharacter is ‘^]’.#下面是请求首部GET/centos6.repo http/1.1 Host:172.16.0.1#下面是响应首部部分HTTP/1.1200 OKDate:Sat, 24 Aug 2013 03:06:48 GMTServer:Apache/2.2.15 (CentOS)Last-Modified:Sat, 17 Aug 2013 10:06:13 GMTETag:”20de6-12d-4e421db6ce2c1″Accept-Ranges:bytesContent-Length:301Connection:closeContent-Type:text/plain; charset=UTF-8#下面是响应主体部分[base]name=CentOS$releasever $basearch on local server 172.10.0.1baseurl=http://172.16.0.1/cobbler/ks_mirror/centos-6.4-$basearch/gpgcheck=0[epel]name=FedoraEPEL for CentOS$releasever $basearch on local server 172.16.0.1baseurl=http://172.16.0.1/fedora-epel/$releasever/$basearch/gpgcheck=0Connectionclosed by foreign host.

web服务器软件httpd

[root@stu2~]# rpm -ql httpd #查看安装httpd软件包生成的列表#下面是几个比较重要的/etc/httpd#运行目录/etc/httpd/conf/httpd.conf#主配置文件/etc/httpd/conf.d/*.conf#扩展配置文件/etc/rc.d/init.d/httpd#服务脚本/var/www/cgi-bin# CGI脚本路径/var/www/html#网页文件目录

启动httpd服务提供主页面进行验证:

[root@stu2~]# service httpd restartStoppinghttpd:[ OK ]Startinghttpd:[ OK ]提供默认主页面:index.html#cd/var/www/html#vimindex.html<html><title>Test Page</title><boby><h1>Helloworld</h1><h2>Studyhard</h2></boby></html>

四、详解httpd的工作属性:

在主配置文件/etc/httpd/conf/httpd.conf中配置文件的构成:

[root@stu2conf]# grep “Section” httpd.conf###Section 1: Global Environment #全局配置:对主服务器或虚拟机都有效,且有些功能是服务器自身工作属性;###Section 2: ‘Main’ server configuration #对主服务器的配置###Section 3: Virtual Hosts #对虚拟主机及属性定义

2、配置所选用的MPM的属性

[root@stu2conf]# httpd –l #查看核心模块Compiledin modules: core.c prefork.c http_core.c mod_so.c[root@stu2conf]# httpd -t -D DUMP_MODULES #查看扩展模块,只列了一小部分LoadedModules: core_module (static) mpm_prefork_module (static) http_module (static) so_module (static)

要想配置使用编译进不同MPM的httpd,编辑/etc/sysconfig/httpd配置文件,定义如下行:

[root@stu2conf]# vim /etc/sysconfig/httpd#HTTPD=/usr/sbin/httpd.worker#将其改为启动项[root@stu2conf]# service httpd restartStoppinghttpd:[ OK ]Startinghttpd:[ OK ][root@stu2conf]# ps aux | grep httpdroot3361 0.0 0.3 184360 4036 ?Ss 13:41 0:00 /usr/sbin/httpd.workerapache 3364 0.0 0.5 528620 5332 ?Sl 13:41 0:00 /usr/sbin/httpd.workerapache 3368 0.0 0.5 528620 5340 ?Sl 13:41 0:00/usr/sbin/httpd.workerapache 3369 0.0 0.5 528620 5332 ?Sl 13:41 0:00 /usr/sbin/httpd.workerroot3478 0.0 0.0 103244 832 pts/0 S+ 13:41 0:00 grep httpd

4、配置站点根目录

#mkdir–pv /website/htdocs#cd/website/htdocs#touchtest.txt编辑test.txt在里面写上test page然后修改配置文件DocumentRoot”/website/htdocs”#httpd–t#servicehttpd restart

5、配置页面文件访问属性

<Directory”/website/htdocs”>Options Indexes FollowSymLinksAllowOverride NoneOrder allow,denyAllow from all</Directory>Indexes: 是否允许索引页面文件,建议关闭;FollowSynLinks: 是否跟随软链接文件;ExecCGI:是否允许执行CGI脚本

然后修改配置文件在定义路径别名的区段添加上一行

Alias/images/ "/www/static/"

重新加载后进行访问:

9.脚本别名

在主配置文件中找到定义脚本别名的区域添加一行

ScriptAlias/cgi-bin/ "/website/cgi-bin/"

#mkdir–pv /website/cgi-bin/#vim/website/cgi-bin/test.sh#!/bin/bashcat<< EOFContent-Type:text/html<pre>Thehostname is:`/bin/hostname`Thetime is:`date`</pre>EOF#chmod+x /website/cgi-bin/test.sh#bash–n /website/cgi-bin/test.sh

重新加载后进行访问

10、基于用户访问控制

首先建立用户帐号文件

htpasswd -c-m /path/to/password_file USERNAME

上帝从不埋怨人们的愚昧,人们却埋怨上帝的不公

web服务器apache理论、实践详解

相关文章:

你感兴趣的文章:

标签云: