1.在虛擬主機(jī)中實(shí)現(xiàn)用戶驗(yàn)證
創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括興安網(wǎng)站建設(shè)、興安網(wǎng)站制作、興安網(wǎng)頁(yè)制作以及興安網(wǎng)絡(luò)營(yíng)銷(xiāo)策劃等。多年來(lái),我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,興安網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到興安省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
[root@localhost logs]# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf
DocumentRoot "/data/www"
ServerName www.123.com
ServerAlias www.aaa.com
#用戶認(rèn)證
AllowOverride AuthConfig
AuthName "study"
AuthType Basic
AuthUserFile /data/.htpasswd //存用戶名和密碼
require valid-user
#ErrorLog "logs/dummy-host.example.com-error_log" //錯(cuò)誤日志
#CustomLog "logs/dummy-host.example.com-access_log" common //正常日志
/data/.htpasswd文件的生成:
/usr/local/apache2/bin/htpasswd -c -m(md5)/data/.htpasswd [username] //第一次使用時(shí)要添加-c選項(xiàng),若第二次還是用則會(huì)覆蓋第一次的所產(chǎn)生的文件。
New password:
Re-typenew password:
[root@localhost MySQL]# cat /data/.htpasswd
aming1:$apr1$60e7Z/11$31yiwDyX0iRSVGAuznpwn.
[root@localhost ~]# apache -t
Syntax OK
[root@localhost ~]# apache restart
注:
增加第二個(gè)用戶的時(shí)候,就不要加-c了,因?yàn)?c是創(chuàng)建的意思,如果加上會(huì)把這個(gè)文件重寫(xiě)。
再次用瀏覽器進(jìn)入論壇會(huì)出現(xiàn)以下窗口:
Content-Type: text/html; charset=iso-8859-1
[root@localhost mysql]# curl -x127.0.0.1:80 www.123.com -I
HTTP/1.1 301 Moved Permanently
Date: Sat, 02 May 2015 22:02:58 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Location: http://www.aaa.com/
Cache-Control: max-age=0
Expires: Sat, 02 May 2015 22:02:58 GMT
Content-Type: text/html; charset=iso-8859-1
注:301與302區(qū)別——301暫時(shí),302永久 ,401 Authorization Requied需要認(rèn)證
配置apache的訪問(wèn)日志
[root@localhost logs]# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf
添加如下內(nèi)容
#配置日志
ErrorLog "/usr/local/apache2/logs/dummy-host.example.com-error_log"
SetEnvIf Request_URI ".*\.gif$" p_w_picpath-request
SetEnvIf Request_URI ".*\.jpg$" p_w_picpath-request
SetEnvIf Request_URI ".*\.png$" p_w_picpath-request
SetEnvIf Request_URI ".*\.bmp$" p_w_picpath-request
SetEnvIf Request_URI ".*\.swf$" p_w_picpath-request
SetEnvIf Request_URI ".*\.js$" p_w_picpath-request
SetEnvIf Request_URI ".*\.css$" p_w_picpath-request
CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/oem.discuz.qq.com-error_%Y%m%d.log 86400" combined env=!p_w_picpath-request
注:路徑最好寫(xiě)絕對(duì)路徑,同時(shí)也要寫(xiě)對(duì),在實(shí)驗(yàn)時(shí)由于自己未寫(xiě)對(duì)路徑就出現(xiàn)了錯(cuò)誤。
若將生成日志的文件路徑寫(xiě)錯(cuò)會(huì)出現(xiàn)以下錯(cuò)誤。
[root@localhost logs]# curl -u aming1:123456 -x127.0.0.1:80 www.123.com -I
curl: (7) couldn't connect to host
[root@localhost logs]# curl -u aming1:123456 -x127.0.0.1:80 www.aaa.com -I
curl: (7) couldn't connect to host
配置靜態(tài)文件緩存
[root@localhost logs]# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf
添加如下內(nèi)容
#配置靜態(tài)文件緩存
ExpiresActive on
ExpiresByType p_w_picpath/gif "access plus 1 days"
ExpiresByType p_w_picpath/jpeg "access plus 24 hours"
ExpiresByType p_w_picpath/png "access plus 24 hours"
ExpiresByType text/css "now plus 2 hour"
ExpiresByType application/javascript "now plus 2 hours"
ExpiresByType application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0 min"
注:我們?cè)谠O(shè)置js文件時(shí)格式為x-javascript,curl后不能達(dá)到我們要的效果,我們將其該為javascript就可以了。
[root@localhost www]# curl -u aming1:123456 -x127.0.0.1:80 www.aaa.com/2.js -I
HTTP/1.1 200 OK
Date: Sat, 02 May 2015 22:43:13 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Last-Modified: Sat, 02 May 2015 22:41:14 GMT
ETag: "23277-0-5152106b3c108"
Accept-Ranges: bytes
Cache-Control: max-age=0
Expires: Sat, 02 May 2015 22:43:13 GMT
Content-Type: application/javascript
[root@localhost www]# curl -u aming1:123456 -x127.0.0.1:80 www.aaa.com/2.js -I
HTTP/1.1 200 OK
Date: Sat, 02 May 2015 22:44:14 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Last-Modified: Sat, 02 May 2015 22:41:14 GMT
ETag: "23277-0-5152106b3c108"
Accept-Ranges: bytes
Cache-Control: max-age=7200
Expires: Sun, 03 May 2015 00:44:14 GMT
Content-Type: application/javascript
這里補(bǔ)充說(shuō)明一點(diǎn),最后一行已經(jīng)告訴了我們文件類(lèi)型,比如這里是 Content-Type: application/javascript,如果對(duì)于 css 文件,則為 Content-Type: text/css ,對(duì)于 jpg/jpeg 文件,則為 Content-Type: p_w_picpath/jpeg ,只需要將該類(lèi)型配置到 ExpiresByType 中就可以對(duì)相應(yīng)文件進(jìn)行緩存了。
配置防盜鏈
添加如下內(nèi)容:
#配置防盜鏈
SetEnvIfNoCase Referer "^http://www.123.com" local_ref
SetEnvIfNoCase Referer ".*www.aaa.com" local_ref
SetEnvIfNoCase Referer "^$" local_ref
Order Allow,Deny
Allow from env=local_ref
實(shí)驗(yàn)結(jié)果:
[root@localhost www]# curl -u aming1:123456 -e"www.aaa.com/safsaf" -x127.0.0.1:80 www.aaa.com/1.txt -I
HTTP/1.1 200 OK
Date: Sat, 02 May 2015 22:59:35 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Last-Modified: Sat, 02 May 2015 15:22:31 GMT
ETag: "2325b-a-5151ae5c57002"
Accept-Ranges: bytes
Content-Length: 10
Cache-Control: max-age=0
Expires: Sat, 02 May 2015 22:59:35 GMT
Content-Type: text/plain
[root@localhost www]# curl -u aming1:123456 -e"http://www.123.com/safsaf" -x127.0.0.1:80 www.aaa.com/1.txt -I
HTTP/1.1 200 OK
Date: Sat, 02 May 2015 23:00:34 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Last-Modified: Sat, 02 May 2015 15:22:31 GMT
ETag: "2325b-a-5151ae5c57002"
Accept-Ranges: bytes
Content-Length: 10
Cache-Control: max-age=0
Expires: Sat, 02 May 2015 23:00:34 GMT
Content-Type: text/plain
[root@localhost www]# curl -e "www.baidu.com" -u aming1:123456 -x127.0.0.1:80 www.aaa.com/1.txt -I
HTTP/1.1 403 Forbidden
Date: Sat, 02 May 2015 22:57:23 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Content-Type: text/html; charset=iso-8859-1
[root@localhost www]# curl -e "www.qq.com" -u aming1:123456 -x127.0.0.1:80 www.aaa.com/1.txt -I
HTTP/1.1 403 Forbidden
Date: Sat, 02 May 2015 22:57:44 GMT
Server: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28
Content-Type: text/html; charset=iso-8859-1
訪問(wèn)控制
Order deny,allow
Deny from all
Allow from 127.0.0.1
針對(duì)請(qǐng)求的uri去限制
Order deny,allow
Deny from all
Allow from 127.0.0.1
某個(gè)某陸下禁止解析php
php_admin_flag engine off
Order deny,allow
Deny from all