自己沒事會整理一些小知識,複習原來的同時也幫助新手。
vvvvvvvvvvvvv開啟apache目錄驗證vvvvvvvvvvvvvv
htpasswd -cm uers redhat //redhat使用者是虛擬的使用者uers為生成加密使用者的密碼檔案
# htpasswd -cm uers redhat //第二次這樣輸入它會把第一次的輸入覆蓋掉
[root@redhat httpd]# cat uers
redhat:$apr1$8X/YcAoY$xlwRboAtWudU26krVPoyD1
# htpasswd -m uers westos //少個c就不會覆蓋原先的
[root@redhat httpd]# cat uers
redhat:$apr1$8X/YcAoY$xlwRboAtWudU26krVPoyD1
westos:$apr1$HUl2zxD9$CI2YcuhNO68hEqch3ttMn1
編輯Apache的配置檔案
<Directory "/var/www/html/admin">
AllowOverride ALL
authuserfile "/etc/httpd/uers"
authname "input your name "
authtype basic
require valid-user //指的是所有使用者
# require user admin //這個指的是單個使用者
</Directory>
測試時ip+admin(目錄)
vvvvvvvvvvvvvvapache虛擬主機的配置vvvvvvvvvvvvvvvvv
cd /var/www //2個釋出目錄
# mkdir html1
# cd html1/
vim index.html
/var/www/html
vim index.html
apache的配置檔案
NameVirtualHost *:80 //開啟80埠
<VirtualHost *:80> //配置apche的配置檔案
DocumentRoot /var/www/html //這個是Apache預設釋出目錄
ServerName redhat.example.com
ErrorLog logs/redhat.example.com-error_log
CustomLog logs/redhat.example.com-access_log common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html1 //這個目錄和上面那個不是一個目錄,看清這個是“html1”
ServerName www.example.com
ErrorLog logs/www.example.com-error_log
CustomLog logs/www.example.com-access_log common
</VirtualHost>
客戶端
# vim /etc/hosts
192.168.3.30 redhat.example.com
192.168.3.30 www.example.com 在瀏覽器中分別輸入redhat.example.com www.example.com域名
vvvvvvvvvvvvvvvvvvvvApache加密證書的製作vvvvvvvvvvvvvvvvvvvvvvvvvvv
# yum install mod_ssl -y //按裝mod_ssl軟體包
/etc/pki/tls/private
# rm -rf localhost.key //預設安裝好軟體包回生成一對私鑰
/etc/pki/tls/certs
# rm -rf localhost.crt //刪除公鑰
# make localhost.crt //自己生成一對公私鑰
localhost.crt localhost.key
# /etc/init.d/httpd restart //重啟apche服務會提示輸入密碼
Enter pass phrase:
# openssl --help
# openssl genrsa 1024
# openssl genrsa 1024 > localhost.key //匯出私鑰
# make localhost.crt //編輯公鑰
# /etc/init.d/httpd restart //重啟系統發現不會提示讓你輸入密碼
redhat.example.com
https://redhat.example.com/ //發現不同的域名訪問到的內容是相同的,說明虛擬主機有問題 redhat.example.com
/etc/httpd/conf.d/ //配置ssl.conf它所使用的埠為443
# vim ssl.conf
NameVirtualHost *:443 //寫在ssl檔案中的其實就是Apache虛擬主機的內容,port由80變為443,只是多了帶色的那幾行,僅此而已
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
DocumentRoot /var/www/html
ServerName redhat.example.com
ErrorLog logs/redhat.example.com-error_log
CustomLog logs/redhat.example.com-access_log common
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
DocumentRoot /var/www/html1
ServerName www.example.com
ErrorLog logs/www.example.com-error_log
CustomLog logs/www.example.com-access_log common
</VirtualHost>
# /etc/init.d/httpd restart
客戶端測試
redhat.example.com