天天看點

HTTP服務配置

Web服務:

http (超文本傳輸協定) 80/TCP

https 443/TCP

html:

http-->ascii 網頁傳輸時轉換為ASCII碼傳輸

*.jpg *.mp3 轉換為二進制檔案,傳輸後需要特定的×××才能還原

www,1995,http 0.9協定 誕生

将網頁中的圖檔和文字和聲音檔案編碼成文本協定才能傳輸!浏覽器通過flash插件調用本地的圖檔和聲音的應用程式才能顯示圖檔和聲音,浏覽器本身隻能顯示超文本檔案!

網頁中的圖檔和資料是一個個object對象!

object: TCP ,每個請求需要三次握手

http:0.9 --> http 1.0(MIME) -- http 1.1(keepalive)

keepalive,為keepalive定義逾時時間2秒鐘,若2秒鐘内沒有請求,則斷開與其連接配接。定義一次最大請求連接配接次數,若超過則斷開連接配接,讓其重新排隊等待伺服器響應

http:資料報封包格式

require請求

response響應

URI 統一資源辨別符,說明在網際網路上怎樣辨別資源

URL 統一資源定位符 protocol://server:port/path/to/file eg:http://www.magedu.com:80/logo.gif

URN 統一資源

http的方法:

GET 擷取資源資料

POST 向伺服器傳輸資料并要求伺服器處理

HEAD 隻看資源是否存在,擷取頭部資訊即可

PUT 向指定資源位置上傳最新内容

TRACE

OPTIONS

DELETE 删除指定資源

CONNECT

HTTP協定響應碼:

1xx:資訊

2xx:正常響應資訊

3xx:重定向

4xx;用戶端錯誤

5xx:伺服器端錯誤

web伺服器軟體:

apache (httpd --> a patchy server -->apache(ASF:project,httpd)) 穩定

iis 應用程式服務

nginx 輕量級,靜态響應快,時間響應機制巨快,響應請求消耗資源少

lighttpd 輕量級,配置檔案文法簡單易懂,性能出衆

優化方案:

nginx前端接待使用者請求,然後傳至apache響應,此時apache 做反向代理伺服器

具有互動能力的稱為動态頁面

CGI:comman gateway interface 通用網關接口

perl腳本比bash腳本更強大

php 面向對象,

jsp :java server page,與php相比性能好

jvm:java vmware(java 虛拟機)

應用一個動态網頁,需要一個cgi接口進行互動

CGI響應方式:

apche接受一個使用者請求時會立刻生成一個程序,如果使用者請求一個動态頁面則還需要再生成一個子程序!apache 中每一個使用者的程序都是獨立的!

子產品化的響應方式:

apche接受一個使用者請求時會立刻生成一個程序,如果使用者請求一個動态頁面則在這個程序中響應,把這個程序當成一個子產品響應,當下一個使用者申請同樣的程序時,還調用這個子產品

FASTCGI響應機制;

事先由伺服器建立空閑程序等待響應,當接受一個使用者請求時,則通過一個接口響應使用者的請求在一個空閑程序中,當使用者請求結束後伺服器則結束這個程序!

JSP:

websphere (IBM)

weblogic (Oracle)

jboss

Tomcat

php:

apache ,php

asp ,asp.net

IIS

BBS:

app

RDBMS:關系型資料庫管理系統

Oracle

mysql

sql server

NOSQL:非關系型資料庫(處理海量資料)

mongoDB

IN-memory DB:記憶體資料庫

LAMP:linux apache mysql php

LNMP:linux nginx mysql php

http://httpd.apache.org

apache 采用子產品化設計;

安裝http:

===============================================

[root@stu33 ~]# yum list all http*

Loaded plugins: rhnplugin

This system is not registered with RHN.

RHN support will be disabled.

Installed Packages

httpd.i386 2.2.3-31.el5 installed

Available Packages

httpd-devel.i386 2.2.3-31.el5 Server

httpd-manual.i386 2.2.3-31.el5 Server

由于selinux 限制,安裝之前先關閉selinux

[root@stu33 ~]# getenforce

Enforcing

[root@stu33 ~]# setenforce 0 #臨時關閉selinux

# vim /etc/sysconfig/selinux

修改内容為SELINUX=permissive #永久關閉selinux

[root@stu33 ~]# rpm -qc httpd #檢視生成的檔案

/etc/httpd/conf.d/proxy_ajp.conf

/etc/httpd/conf.d/welcome.conf

/etc/httpd/conf/httpd.conf

/etc/httpd/conf/magic

/etc/logrotate.d/httpd

/etc/rc.d/init.d/httpd

/etc/sysconfig/httpd

.....

[root@stu33 ~]# rpm -ql httpd | grep ".*bin.*"

/usr/bin/ab

/usr/bin/htdbm

/usr/bin/htdigest

/usr/bin/htpasswd

....

[root@stu33 ~]# rpm -ql httpd | grep "www"

/var/www

/var/www/html #預設存放網頁的位置

/var/www/icons

/var/www/icons/README

MPM:多路處理子產品

prefork

每一個請求用一個程序來響應

穩定性好、安全性好

worker

每一個請求用一個線程來響應,把一個程序生成一堆線程來響應

輕量級建立和銷毀,資源消耗低

當多個使用者連接配接進來時,怎樣去響應連接配接請求的稱為多路處理子產品

[root@stu33 ~]# service httpd start #啟動httpd服務

Starting httpd: httpd: apr_sockaddr_info_get() failed for stu33.magedu.com.localdomain

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName [OK]

#此時會報錯,因為此時會解析主機,沒有影響忽略此時錯誤

#yum install httpd-manual #安裝httpd幫助文檔

*************************************************

# vim /etc/httpd/conf/httpd.conf 配置檔案

ServerTokens OS

ServerRoot "/etc/httpd"

PidFile run/httpd.pid

Timeout 120

KeepAlive Off #off狀态對伺服器性能有好處,on對使用者請求體驗好

MaxKeepAliveRequests 100

KeepAliveTimeout 15

# #prefork MPM 下面的是prefork MPM定義

<IfModule prefork.c>

StartServers 8 #啟動程序數

MinSpareServers 5 #最小空閑程序數

MaxSpareServers 20 #最多空閑程序數

ServerLimit 256 # 定義maxclient超出上限

MaxClients 256 #最大程序數

MaxRequestsPerChild 4000 #定義一個程序最多響應幾個請求

# #worker MPM 下面是 worker MPM定義

<IfModule worker.c>

StartServers 2

MaxClients 150

MinSpareThreads 25

MaxSpareThreads 75

ThreadsPerChild 25

MaxRequestsPerChild 0 #0表示不作限制

</IfModule>

Listen 80

Listen 12.34.56.78:80 #表示監聽12.34.56.78的80端口,可以自定義監聽IP的80端口

# Example: 下面的是加載子產品

# LoadModule foo_module modules/mod_foo.so

LoadModule auth_basic_module modules/mod_auth_basic.so

LoadModule auth_digest_module modules/mod_auth_digest.so

LoadModule authn_file_module modules/mod_authn_file.so

#

。。。。。

Include conf.d/*.conf

#ExtendedStatus On #顯示狀态資訊 ,預設不啟用

User apache

Group apache #指定服務的使用者群組

ServerAdmin root@localhost

#ServerName www.example.com:80 #這裡就是上面報錯的原因,啟用後修改為本機的主機名

DocumentRoot "/var/www/html" #網頁檔案儲存的位置

<Directory /> #定義目錄的通路屬性

Options FollowSymLinks

AllowOverride None

</Directory>

<Directory "/var/www/html"> #下面定義網頁檔案的目錄屬性

Options Indexes FollowSymLinks #允許建立軟連結

Options Indexes SymLinksifOwnerMatch #允許使用者比對的才能建立連結

Options Indexes ExecCGI #允許使用CGI接口

Options Indexes MultiViews #允許多視圖

==============================================

AllowOverride AuthConfig/none #定義基于認證的允許

AuthName “wanggzhen” #認證名稱

AuthType Basic #認證類型,還可以有MD5認證這裡使用最簡單的方式basic

AuthUserFile /etc/httpd/conf/.htpasswd #建立需要認證的使用者的密碼的配置檔案我們自己建立

#htpasswd

用法:htpasswd [ -c ] [ -m ] [ -D ] passwdfile username

-c Create the passwdfile.

-m Use MD5 encryption for passwords.

-D Delete user.

#htpasswd -cm /etc/httpd/conf/.htpasswd gentoo

#htpasswd -c /etc/httpd/conf/.htpasswd centos #這裡不需要再建立密碼檔案,第一次需要建立密碼檔案

[root@stu33 ~]# htpasswd -D /etc/httpd/conf/.htpasswd wz

Deleting password for user wz

AuthGroupFile /etc/httpd/conf/.htgroup #建立需要認證的使用者組的密碼檔案

Require user gentoo #認證的使用者gentoo

Require group developers 需要認證的組develpers

============================================

Order allow,deny #基于IP的ACL

Allow from all #接受所有

dengy from 192.168.0.38 #拒絕此ip的通路,,靠後的優先級高

</Directory>

<IfModule mod_userdir.c>

UserDir disable

#UserDir public_html #若啟用這一項則下面給的注釋符需要去掉

</IfModule>

#<Directory /home/*/public_html>

# AllowOverride FileInfo AuthConfig Limit

# Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec

# <Limit GET POST OPTIONS>

# Order allow,deny

# Allow from all

# </Limit>

# <LimitExcept GET POST OPTIONS>

# Order deny,allow

# Deny from all

# </LimitExcept>

#</Directory>

DirectoryIndex index.html index.html.var

AccessFileName .htaccess #打算對某個目錄的通路控制,則在那個目錄中建立這個.htaccess檔案,檔案内容為:

AuthName "wangzhen"

AuthType Basic

AuthUserFile /home/wangzhen/.htpasswd

Require user centos

然後#htpasswd -cm /home/wangzhen/.htpasswd centos

<Files ~ "^\.ht">

Order allow,deny

Deny from all

</Files>

TypesConfig /etc/mime.types

HostnameLookups Off #主機名解析可以關閉

ErrorLog logs/error_log #錯誤日志路徑

LogLevel warn #定義錯誤日志級别

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat "%h %l %u %t \"%r\" %>s %b" common

LogFormat "%{Referer}i -> %U" referer

LogFormat "%{User-agent}i" agent

%b相應資訊的大小 %{Referer}i引用 %{User-Agent}i使用者請求

%h遠端主機的IP位址 %l遠端使用者的使用者名 %t時間 %r請求資訊的第一行 %>狀态碼

#CustomLog logs/access_log common #通路日志,預設沒有啟用

CustomLog logs/access_log combined #通路日志的格式

ServerSignature On #伺服器簽署

Alias /error/ "/var/www/error/" #為/error/定義别名/var/www/error

AddDefaultCharset UTF-8 #預設使用的是UTF-8可能會導緻中文亂碼,可以注釋掉

************************************************

#ps aux | grep "httpd" #顯示與httpd有關的程序的資訊

apache benchmark #對apache壓力測試

ab:

-n 模拟要發起的請求數

-c 模拟多少個使用者并發發起請求

eg:ab -n 1000 -c 2000 http://172.16.33.1

上一篇: 配置Ftp服務
下一篇: NFS服務配置

繼續閱讀