RedHat (httpd):
rpm 包:
源碼編譯
elinks http://192.168.21.123 (交互式,純文本)
-dump 顯示網頁以後直接退出,不在進行交互式
-source 顯示網頁源碼
curl http://192.168.21.123
httpd: SELinux 事先將其配置爲 permissive 或 disabled
httpd:
/usr/sbin/httpd (MPM: preforx)
httpd: root,root (master process)
httpd: apache,apache (worker process)
/etc/rc.d/init.d/httpd
port:(80/tcp), (ssl:443/tcp)
/etc/httpd/ :工做跟目錄,至關於程序安裝目錄
/etc/httpd/conf/ :配置文件目錄
主配置文件 :httpd.conf
/etc/httpd/conf.d/*.conf 是主配置文件的組成部分
/etc/httpd/modules/ :模塊目錄
/etc/httpd/logs/ :日誌目錄
日誌文件有兩類:訪問日誌 access_log,錯誤日誌:err_log
/var/www/
html
cgi-bin
cgi :Common Gateway Interface
Client --> httpd (index.cgi) --> Spawn process (index.cgi) --> httpd --> client
fastcgi :
http://httpd.apache.org
本身安裝幫助手冊
# yum -y install httpd-manual
http://192.168.21.117/munual
httpd.conf:
directive value
指令不區分大小寫
value 區分大小寫
MPM : Multi-Processing Modules
mpm_winnt
prefork (一個請求用一個進程響應)
worker (一個請求用一個線程響應,(啓動多個進程,每一個進程生成多個線程))
event (一個進程處理多個請求)
# rpm -ql | grep sbin
# httpd -l
# less /etc/sysconfig/httpd
#prefork 模型
<IfModule prefork.c>
StartServers 8 #httpd啓動是啓動的進程個數
MinSpareServers 5 #保持最少空閒進程的個數
MaxSpareServers 20 #最多空閒進程的個數
ServerLimit 256 #限制MaxClients
MaxClients 256 #最大同時鏈接的請求數
MaxRequestsPerChild 4000 #單個進程最大處理的請求數,超過閥值後kill以後從新生成一個新的進程
</IfModule>
#worker 模型
<IfModule worker.c>
StartServers 4 #啓動進程的個數
MaxClients 300 #最大同時鏈接的請求數
MinSpareThreads 25 #最小的空閒總線程數
MaxSpareThreads 75 #最大的空閒總線程數
ThreadsPerChild 25 #每一個進程的線程數
MaxRequestsPerChild 0
</IfModule>
#監聽地址和端口,能夠有多行
Listen [IP:]port
Listen 80
Listen 172.16.10.1:8080
#包含的配置文件
Include cond.d/*.conf
#URL根目錄相對應的本地路徑
DocumentRoot "/var/www/html"
URL路徑<>本地文件路徑,URL是相對於DocumentRoot的路徑而言
<Directory "/var/www/html">
Options None
AllowOverride None
Order allow,deny
Allow from 192.168.100.0/24
</Directory>
Options
None :不支持任何選項
Indexes :容許索引目錄 (不安全的)
FollwSymLinks :容許訪問符號連接指向的源文件,不要開啓,影響訪問速度
Includes :容許執行服務端包含(SSI) (不安全的)
ExecCGI :容許運行CGI腳本
Multiviews :根據客戶端來源的語言顯示相應的資源
All :啓用全部選項
AllowOverride : 是否覆蓋Order項,none all,或者使用密碼驗證等
#使用用戶密碼驗證:
AllowOverride AuthConfig
Authtype Basic
AuthName "受限制的訪問站點"
AuthUserFile "/etc/httpd/conf/htpasswd"
AuthGroupFile "/etc/httpd/conf/htgroup"
Require user user_name | valid-user | group mygroup
# user_name 容許登陸的用戶
# valid-user 容許全部的用戶登陸
# group mygroup 容許登陸的用戶組
Order :用於定義基於主機的訪問控制功能,IP,網絡地址或主機定義訪問控制機制
order allow,deny
allow from xx
deny from xx
地址的表示方式
IP
network/netmask
HOSTNAME :www.a.com
DOMAINNAME :test.com
Partial IP :172.1172.16.0.0/16
創建AuthUserFile
[root@rs1 ~]# htpasswd -c -m /etc/httpd/conf/htpasswd hadoop
New password:
Re-type new password:
Adding password for user hadoop
向存在的htpasswd 中添加用戶
[root@rs1 ~]# htpasswd -m /etc/httpd/conf/htpasswd hale
New password:
Re-type new password:
Adding password for user hale
建立AuthGroupFile
[root@rs1 ~]# cd /etc/httpd/conf
[root@rs1 conf]# ll
total 56
-rw-r--r-- 1 root root 88 Dec 16 18:02 htpasswd
-rw-r--r-- 1 root root 34422 Dec 16 15:53 httpd.conf
-rw-r--r--. 1 root root 13139 Oct 16 2014 magic
[root@rs1 conf]# vim htgroup
[root@rs1 conf]# httpd -t
Syntax OK
vim htgroup
mygroup:hadoop hale #此處添加的用戶必須存在於 AuthUserFile
#定義URI別名,它有本身的本地文件路徑,與DocumentRoot根無關
# curl http://192.168.21.117/icons/
Alias /icons/ "/var/www/icons/"
<Directory "/var/www/icons">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
apache 虛擬主機:
apache:服務器,Host,物理主機
虛擬主機:
一個apache服務器服務於多個不一樣的站點:
apache:
中心主機:
虛擬主機:
基於端口:
IP:80
IP:8080
基於IP:
IP1:80
IP2:80
基於域名:
IP:80
主機名不一樣
www.a.com
www.b.com
www.c.com
apache 2.2
啓用 NameVirtualHost
apache 2.4
直接定義虛擬主機,不須要指令NameVirtualHost
serverName
serverAlias
DocumentRoot "/www/a.com"
<Directory "/www/a.com">
Options None
AllowOverride None
</Directory>
Alias
ErrorLog
CustomLog
<Location "/status">
SetHandler server_status
</Location>
ScriptAlias
要使用虛擬主機,須要先取消中心主機,註釋中心的DocumentRoot便可
虛擬主機的定義:
#DocumentRoot "/var/www/html"
#基於端口和IP的虛擬主機
<VirtualHost 172.16.10.1:80>
ServerName ip1.hale.com
DocumentRoot "www/ip1"
</VirtualHost>
<VirtualHost 172.16.10.2:80>
ServerName ip2.hale.com
DocumentRoot "/www/ip2"
</VirtualHost>
<VirtualHost 172.16.10.1:8080>
ServerName port2.hale.com
DocumentRoot "/www/port2"
</VirtualHost>
#基於主機名的虛擬主機
NameVirtualHost 192.168.10.2:80
<VirtualHost 192.168.10.2:80>
ServerName name1.hale.com
DocumentRoot "/www/name1"
</VirtualHost>
<VirtualHost 192.168.10.2:80>
ServerName name2.hale.com
DocumentRoot "/www/name2"
</VirtualHost>
基於openssl的https
apache的ssl須要 mod_ssl 的支持
# yum install mod_ssl
# rpm -ql mod_ssl
一個apache服務能夠有多個http虛擬主機,但只能有一個https虛擬主機
#使用openssl建立須要的CA,此處直接在http服務器上生成證書
# vim /etc/pki/tls/openssl.cnf
# cd /etc/pki/CA/
# ls
# (umask 077; openssl genrsa 2048 > private/cakey.pem)
# openssl req -new -x509 -key private/cakey.pem -out cacert.pem
# echo 01 > serial
# touch index.txt
# cd /var/www/ssl
# mkdir /var/www/ssl
# cd /var/www/ssl
# (umask 077; openssl genrsa 1024 > https.key)
# openssl req -new -key https.key -out https.csr
# openssl ca -in https.csr -out https.crt -days 3650
# ls
#修改ssl.conf配置
#須要修改的主要配置項,其餘的項目根據需求進行修改
# vim /etc/httpd/conf.d/ssl.conf
<VirtualHost _default_:443>
ServerName https.hale.com
DocumentRoot "/var/www/ssl"
<Directory "/var/www/ssl">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
SSLEngine on
SSLCertificateFile /var/www/ssl/https.crt
SSLCertificateKeyFile /var/www/ssl/https.key
</VirtualHost>
html