天天看点

Linux下Web服务器应用之基础简介

Linux下Web服务器应用之基础简介

<b>一.web服务器基本知识:</b>

WWW 是 World Wide Web 的缩写

URL:&lt;协定&gt;://&lt;主机地址或主机名&gt;[:port]/&lt;目录资源&gt;

协议   http 80 明文 https 加密 (ssl)数字证书 443

<a target="_blank" href="http://blog.51cto.com/attachment/201203/205332116.png"></a>

超文本传输协mime(多用户邮件扩展)smtp(简单邮件传输协议)

      版本:1.0 1.1 keepalive(一次连接多次请求) 

<a target="_blank" href="http://blog.51cto.com/attachment/201203/205353163.png"></a>

web服务器实现方法:

 iis         apache (lamp) 70%            nginx (lnmp)          lighty

中间件:microsoft:iis         ibm:webspere 40%         tomcat

oracle:(ba) weblogic 30%      susion middleware

静态网站: html

动态: asp jsp php cgi asp.net

<b>二.apache服务器</b><b> </b>

Apache服务器简介:

Apache服务器一个主要的特点是完全免费,并且完全公开其源代码,由此用户可根据自身的需要去进行相关模块的开发。Apache服务器另一个主要的特点是其跨平台性,其可在UNIX、Windows、Linux等多种操作系统上运行。如果需要创建一个每天有数百万人访问的Web服务器,Apache可能是最佳选择。

工作组:apache group   ---》asf 

httpd 1.0 2.0 2.2 tomcat

<b>Apache</b><b>安装包:</b>

[root@junjie_www Server]# ls htt*

httpd-2.2.3-22.el5.i386.rpm         //apache主程序

httpd-devel-2.2.3-22.el5.i386.rpm           //开发工具

httpd-manual-2.2.3-22.el5.i386.rpm        //配置手册

system-config-httpd-1.3.3.3-1.el5.noarch.rpm    //图形配置

<b>安装httpd包</b>

[root@www ~]# cd /mnt/cdrom/Server/

[root@www Server]# rpm -ivh httpd-2.2.3-22.el5.i386.rpm

#rpm -ivh httpd-devel-2.2.3-22.el5.i386.rp

# rpm -ivh httpd-manual-2.2.3-22.el5.i386.rpm

# yum -y install httpd-devel

# yum -y install system-config-httpd

<b>配置文件和目录</b>

/etc/httpd #根目录

/etc/httpd/conf          //配置脚本

/etc/httpd/conf.d #额外配置脚本

/etc/httpd/conf.d/welcome.conf #默认主页

/etc/httpd/conf/httpd.conf         #主配置文件

/var/www/html          #网页文件

/var/run/httpd.pid           #运行的父进程的pid

发布主目录配置DocumentRoot

默认文档DirctoryIndex

监听端口Listen

根目录ServerRoot

日志Log:Errorlog,Accesslog

管理员邮件地址ServerAdmin

服务器名ServerName

默认字符集AddDefaultCharset

虚拟目录Alias

目录权限Order、Allow、Deny

用户认证

插件LoadModule

虚拟主机VirtualHost

<b>/etc/httpd/conf/httpd.conf</b><b>配置文件详解:</b>

<b>### Section 1: Global Environment                 #</b><b>第一部分配置(全局配置)</b>

57 ServerRoot "/etc/httpd"          #指定apache的主目录

63 PidFile run/httpd.pid              #指定apache的父进程pid文件

68 Timeout 120                           #链接超时时间,会出现出错信息

<b>【出错信息:</b>1xx  一般性信息            2xx      正常信息

3xx 正常信息 重定向        4xx 错误信息   警告          5xx 严重错误<b>】</b>

74 KeepAlive on         #保持链接(一次链接多次请求)

81 MaxKeepAliveRequests 100          #一次链接多次请求的次数

87 KeepAliveTimeout 15        #一次链接多次请求的时间

100 &lt;IfModule prefork.c&gt;          #派生机制

101 StartServers       8

102 MinSpareServers    5

103 MaxSpareServers   20

104 ServerLimit      256

105 MaxClients       256

106 MaxRequestsPerChild 4000

107 &lt;/IfModule&gt;

[root@junjie_www ~]# httpd -l

134 Listen 80        #监听端口

137 # Dynamic Shared Object (DSO) Support    #支持的动态共享模块

148-199 LoadModule +模块

210 Include conf.d/*.conf      #包含的额外配置文件

231 User apache        #apache运行所有者

232 Group apache           #apache运行所属组

[root@junjie_www ~]# rpm -q --scripts httpd #安装时执行的其它脚本

<b>234 ### Section 2: 'Main' server configuration   #</b><b>第二部分配置(主要服务配置)</b>

251 ServerAdmin root@localhost      #网站管理员邮箱

265 #ServerName www.example.com:80     #网站名称

274 UseCanonicalName Off        #与虚拟主机有关,保持off

281 DocumentRoot "/var/www/html"          #网站主目录(网页文件)

#/etc/httpd/conf.d/welcome.conf     #默认主页

291 &lt;Directory /&gt;           #目录安全性

292     Options FollowSymLinks

293     AllowOverride None

294 &lt;/Directory&gt;

306 &lt;Directory "/var/www/html"&gt;

311 #   Indexes(目录浏览) Includes FollowSymLinks(链接跟踪支持) SymLinksifOwnerMatch ExecCGI     MultiViews

320     Options Indexes(目录浏览) FollowSymLinks(符号链接)

327     AllowOverride None      #身份验证(none表示不支持)

332     Order allow,deny           #来源验证

333     Allow from all

335 &lt;/Directory&gt;

<a target="_blank" href="http://blog.51cto.com/attachment/201203/205431288.png"></a>

作如下配置,并重启httpd

客户段测试,可以看到如下内容(若download下没网页文件,就会显示文件)

<b>linuxde</b><b>一个文本浏览器:</b>

<b>[root@www  Server]# rpm -ivh lynx-2.8.5-28.1.el5_2.1.i386.rpm</b>

<b>[root@junjie_www Server]# lynx http://10.106.6.254</b>

<b>安全性</b>

windows: (安全---》目录安全性 1.身份验证   2.来源控制   3.加密通讯)

&lt;Directory 目录&gt;目录安全性

    Options FollowSymLinks

     AllowOverride None

 &lt;/目录&gt;

<b>身份验证 </b>

AllowOverride all

.htaccess (说明文件) (站点主目录里面)

.htpasswd(账号库)

[root@junjie_www html]# cat .htaccess

authuserfile /var/www/html/.htpasswd

authtype basic

authname   "please input your name and password"

require        valid-user

[root@junjie_www html]# htpasswd -c .htpasswd qq (首次使用需要-c选项)

[root@junjie_www html]# htpasswd .htpasswd qq1(第二次使用需要-c选项)

客户端测试:出现如下验证信息:(需要输入正确的用户名与密码)

<a target="_blank" href="http://blog.51cto.com/attachment/201203/205546103.png"></a>

<b>来源控制</b>

【 Order allow,deny

    Allow from all】

【Order allow,deny

    Allow from 192.168.2.0/24

     deny from 192.168.2.1】

【Order deny,allow

349 &lt;IfModule mod_userdir.c&gt;

355     UserDir disable         #用户的目录安全性

362     #UserDir public_html     ##打开此行,创建个人主页,取消注释

364 &lt;/IfModule&gt;

/var/log/httpd /    #日志目录

/home/$USER/public_html/   #都要有可读权限

370 #&lt;Directory /home/*/public_html&gt;       #个人目录的安全性

371 #    AllowOverride FileInfo AuthConfig Limit #一些限制

372 #    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoE    xec        #一些可用参数

373 #    &lt;Limit GET POST OPTIONS&gt;

374 #        Order allow,deny

375 #        Allow from all

376 #    &lt;/Limit&gt;

377 #    &lt;LimitExcept GET POST OPTIONS&gt;

378 #        Order deny,allow

379 #        Deny from all

380 #    &lt;/LimitExcept&gt;

381 #&lt;/Directory&gt;

391 DirectoryIndex index.html index.html.var          #支持的目录文件

398 AccessFileName .htaccess     #用于用户验证的信息

413 TypesConfig /etc/mime.types

424 DefaultType text/plain

444 HostnameLookups Off

472 ErrorLog logs/error_log

479 LogLevel warn

485 LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Ag    ent}i\"" combined

486 LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common

487 LogFormat "%{Referer}i -&gt; %U" referer

488 LogFormat "%{User-agent}i" agent

514 CustomLog logs/access_log combined

739 LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl     nn no pl pt pt-BR ru sv zh-CN zh-TW //语言显示的优先级

755 AddDefaultCharset UTF-8     //西欧文字集,若显示中文建议关闭

845 Alias /error/ "/var/www/error/" #错误显示文件

937 #&lt;Proxy *&gt;         #apache的代理功能

938 #    Order deny,allow

939 #    Deny from all

940 #    Allow from .example.com

941 #&lt;/Proxy&gt;

<b>963 ### Section 3: Virtual Hosts4 #                #</b><b>第三部分配置(虚拟主机)</b>

993 #&lt;VirtualHost *:80&gt;

994 #    ServerAdmin [email protected]

995 #    DocumentRoot /www/docs/dummy-host.example.com

996 #    ServerName dummy-host.example.com

997 #    ErrorLog logs/dummy-host.example.com-error_log

998 #    CustomLog logs/dummy-host.example.com-access_log common

999 #&lt;/VirtualHost&gt;

虚拟主机:

1.    物理目录

2.    虚拟目录

3.    基于ip地址的虚拟主机

4.    基于端口的虚拟主机

5.    基于主机头的虚拟主机

本文转自xjzhujunjie 51CTO博客,原文链接:http://blog.51cto.com/xjzhujunjie/808871

继续阅读