---------------------------------------------
配置檔案 RPM 包安裝
Apache /etc/httpd/conf/httpd.conf
--------------------------------------------
apache 配置檔案
--------------------------------
serverRoot "/etc/httpd"
ServerRoot用于指定apache伺服器的配置
檔案及日志檔案存放的根目錄,預設為目錄
“/etc/httpd”
pidFile /var/run/httpd.id
PidFile 用于指定記錄httpd程序号(pid)的檔案
位置,預設值為“/var/run/httpd.pid”
MaxKeepAilveRequests 100
每次連接配接可提出請求的數量,設定為0為不限,預設為100
KeepAileTimeout 15
連接配接兩個請求之間的時間如果超過15秒還未到達,則視為連接配接
中斷
DocumentRoot "/var/www/html"
指定apache伺服器存放網頁的文檔根目錄
##################################
UserDir
UserDir public_html
UserDir 用于設定使用者個人首頁存放的目錄,預設為
“public_html”目錄,即用/home/anyuser/public_html
為每個使用者配置跟人首頁
例如:為使用者user1建立個人首頁
cd /home/user1
mkdir public_html
chown user1.user1 public_html
cd ..
chmod 711 user1
在/home/user1/public_html中建立index.html
使用浏覽器http://localhost/~user1/
虛拟使用者
############################################
Alias 用于設定路徑别名
Alias /doc/ /usr/share/doc/
給 "/usr/share/doc" 設定路徑别名為“/doc/”
************************************************
容器
<Directory / > 設定“/”根目錄的通路權限
options
AllowOverride
Order
Allow
Deny
</ Directory>
五個屬性
options 屬性
options FollowSymLinks Indexes MultiViews
Options 可以組合設定下列選項
ALL:使用者可以在此目錄中做任何事情。
ExecCGI:允許在此目錄中實行CGI程式
FollowSymLinks: 伺服器可使用符号連結指向的檔案或目錄。
Indexes:伺服器可生成此目錄的檔案清單。
None:不允許通路此目錄。
AllowOverride None
AllowOverride 會根據設定的值決定是否讀取目錄中的
.htaccess檔案,來改變運來所設定的權限。
All:讀取.htaccess檔案的内容,修改原來的通路權限
None:不讀取.htaccess檔案
為避免使用者自行建立.htaccess檔案修改通路權限,http.conf
檔案中預設設定每個目錄為:AllowOverride None.
AccessFileName filename
AccessFileName 指令用于指定保護目錄設定檔案的
檔案名稱,預設為“.htaccess”
AccessFileName .acl
-----------------------------------
APACHE虛拟目錄
虛拟目錄的優點:
便于通路
便于移動站點目錄
加大磁盤空間
安全性好
Alias /icons/ "/var/www/icons/"
<Directory "/var/www/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
*******************************
首先在/etc/httpd/conf/httpd.conf
添加 Include vhost/vhost.conf
然後在 /etc/httpd/下建立 mkdir vhost
cd vhost
vi vhost.conf 添加如下内容
Alias /test1 "/root/web/test1/"
<Directory "/root/web/test1">
AllowOverride None
Alias /test2 "/root/web/test2/"
<Directory "/root/web/test2">
然後改變 chmod 755 -R /root/web/test1
chmod 755 -R /root/web/test2
http://localhost/test1
http://localhost/test2
可以增權重限的設定。。。
apache 虛拟目錄
deny 和allow 通路清單的幾種形式
*******************************************
認證和授權
認證類型
basic(常用) digest(再要認證)不常用
建立認證與授權的步驟
建立使用者庫
配置伺服器的保護域
什麼使用者具有通路權限
認證指令
Authname 受保護領域名稱
Authtype 認證方式
Authuserfile 認證密碼檔案
Authgroupfile 認證組檔案
Require use 授權指定使用者
Require group 授權指定組
Require valid-user 授權給認證密碼檔案使用者
建立使用者庫基本認證
htpasswd -c authfile username
密碼檔案格式
username:password
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
使用者認證:
例如:給添加認證
authtype basic
authname "welcome test"
authuserfile /etc/httpd/httppwd
require Valid-user = user test
cd /etc/httpd 下實行 建立使用者名和密碼
檔案名 使用者名
htpasswd -c httppwd test
如果要添加多個使用者那麼隻要第一使用過-c;以後都不用
htpasswd httppwd aaa
并在添加 Alias /test2 "/root/web/test2/"
require Valid-user = user test aaa
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
使用者組授權
allowOverride None
authname "welcome admin"
authgroupfile /etc/httpd/httpgrp
require group admin
vi httpgrp 添加 如下内容:
admin:test aaa
必須在/etc/httpd/httppwd 和/etc/httpd/httpgrp 都存在相同的使用者
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
用.htaccess 檔案授權
AllowOverride all
vi /var/www/test2/.htaccess
authtype basic
require Valid-user
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
建立虛拟web站點
基于IP位址的虛拟主機;基于域名的虛拟主機(同IP,不同端口)
基于IP的虛拟主機的配置
<VirtualHost 169.254.1.234:80>
ServerAdmin [email protected]
DocumentRoot /root/web/test1/
</VirtualHost>
<VirtualHost 169.254.1.233:80>
ServerAdmin [email protected]
DocumentRoot /root/web/test3/
基于端口的虛拟主機配置
Listen 81
Listen 82
<VirtualHost 169.254.1.234:81>
ServerName 169.254.1.234:81
<VirtualHost 169.254.1.234:82>
DocumentRoot /root/web/test3/
ServerName 169.254.1.234:82
-------------------------------------