您的位置:首页 > 运维架构 > Linux

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

2013-05-12 22:26 429 查看
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。/article/4517552.html

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

一.web服务器基本知识:
WWW 是 World Wide Web 的缩写
URL:<协定>://<主机地址或主机名>[:port]/<目录资源>
协议 http 80 明文 https 加密 (ssl)数字证书 443




超文本传输协mime(多用户邮件扩展)smtp(简单邮件传输协议)
版本:1.0 1.1 keepalive(一次连接多次请求)




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
二.apache服务器
Apache服务器简介:
Apache服务器一个主要的特点是完全免费,并且完全公开其源代码,由此用户可根据自身的需要去进行相关模块的开发。Apache服务器另一个主要的特点是其跨平台性,其可在UNIX、Windows、Linux等多种操作系统上运行。如果需要创建一个每天有数百万人访问的Web服务器,Apache可能是最佳选择。
工作组:apache group ---》asf
httpd 1.0 2.0 2.2 tomcat
Apache安装包:
[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 //图形配置
安装httpd包
[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
配置文件和目录
/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
/etc/httpd/conf/httpd.conf配置文件详解:
### Section 1: Global Environment #第一部分配置(全局配置)
57 ServerRoot "/etc/httpd" #指定apache的主目录
63 PidFile run/httpd.pid #指定apache的父进程pid文件
68 Timeout 120 #链接超时时间,会出现出错信息
【出错信息:1xx 一般性信息 2xx 正常信息
3xx 正常信息 重定向 4xx 错误信息 警告 5xx 严重错误
74 KeepAlive on #保持链接(一次链接多次请求)
81 MaxKeepAliveRequests 100 #一次链接多次请求的次数
87 KeepAliveTimeout 15 #一次链接多次请求的时间
100 <IfModule prefork.c> #派生机制
101 StartServers 8
102 MinSpareServers 5
103 MaxSpareServers 20
104 ServerLimit 256
105 MaxClients 256
106 MaxRequestsPerChild 4000
107 </IfModule>
[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 #安装时执行的其它脚本
234 ### Section 2: 'Main' server configuration #第二部分配置(主要服务配置)
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 <Directory /> #目录安全性
292 Options FollowSymLinks
293 AllowOverride None
294 </Directory>
306 <Directory "/var/www/html">
311 # Indexes(目录浏览) Includes FollowSymLinks(链接跟踪支持) SymLinksifOwnerMatch ExecCGI MultiViews
320 Options Indexes(目录浏览) FollowSymLinks(符号链接)
327 AllowOverride None #身份验证(none表示不支持)
332 Order allow,deny #来源验证
333 Allow from all
335 </Directory>




作如下配置,并重启httpd
客户段测试,可以看到如下内容(若download下没网页文件,就会显示文件)



linuxde一个文本浏览器:
[root@www Server]# rpm -ivh lynx-2.8.5-28.1.el5_2.1.i386.rpm
[root@junjie_www Server]# lynx http://10.106.6.254 安全性
windows: (安全---》目录安全性 1.身份验证 2.来源控制 3.加密通讯)
<Directory 目录>目录安全性
Options FollowSymLinks
AllowOverride None
</目录>
身份验证
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选项)
客户端测试:出现如下验证信息:(需要输入正确的用户名与密码)




来源控制
【 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
Allow from 192.168.2.0/24
deny from 192.168.2.1】

349 <IfModule mod_userdir.c>

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

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

364 </IfModule>

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

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

370 #<Directory /home/*/public_html> #个人目录的安全性

371 # AllowOverride FileInfo AuthConfig Limit #一些限制

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

373 # <Limit GET POST OPTIONS>

374 # Order allow,deny

375 # Allow from all

376 # </Limit>

377 # <LimitExcept GET POST OPTIONS>

378 # Order deny,allow

379 # Deny from all

380 # </LimitExcept>

381 #</Directory>

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\" %>s %b \"%{Referer}i\" \"%{User-Ag ent}i\"" combined
486 LogFormat "%h %l %u %t \"%r\" %>s %b" common
487 LogFormat "%{Referer}i -> %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 #<Proxy *> #apache的代理功能
938 # Order deny,allow
939 # Deny from all
940 # Allow from .example.com
941 #</Proxy>
963 ### Section 3: Virtual Hosts4 # #第三部分配置(虚拟主机)
993 #<VirtualHost *:80>
994 # ServerAdmin webmaster@dummy-host.example.com
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 #</VirtualHost>
虚拟主机:
1. 物理目录
2. 虚拟目录
3. 基于ip地址的虚拟主机
4. 基于端口的虚拟主机
5. 基于主机头的虚拟主机
本文出自 “xjzhujunjie” 博客,请务必保留此出处/article/4517552.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: