標籤:
9. 配置防盜鏈
http://www.lishiming.net/thread-71-1-1.html
防止別人的網站,放你網站圖片的連結,
位置一般情況下在 /usr/local/apache/conf/httpd.conf
或者apache 2.2 的 /usr/local/apache2/conf/extra/httpd-vhost.conf
添加
SetEnvIfNoCase Referer "^http://www.ccvita.com" local_ref
SetEnvIfNoCase Referer "^http://ccvita.com" local_refSetEnvIfNoCase Referer "^$" local_ref
<filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif)">
Order Allow,Deny
Allow from env=local_ref
</filesmatch>
還一種寫法,是用正則的,這種寫法在各個版本的apache比較通用。
寫法是
SetEnvIfNoCase Referer "^http://.*\.yourdomin\.com" local_ref
SetEnvIfNoCase Referer ".*\.yourdomin\.com" local_ref
SetEnvIfNoCase Referer "^$" local_ref
<filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif)">
Order Allow,Deny
Allow from env=local_ref
</filesmatch>
10. 存取控制
apache的order allow deny
http://www.lishiming.net/thread-832-1-1.html
apache限制某個目錄下的php檔案沒有執行許可權 http://www.lishiming.net/thread-1000-1-1.html
apache 針對訪問uri 限制ip http://www.lishiming.net/thread-5365-1-1.html
幾種限制ip的方法 http://www.lishiming.net/thread-6519-1-1.html
11. apache rewrite相關,後面講到
apache 限制指定user_agent http://www.lishiming.net/thread-1033-1-1.html
apache 限制某些目錄不能訪問通過rewrite實現 http://www.lishiming.net/thread-3587-1-1.html
apache rewrite 出現死迴圈 http://www.lishiming.net/thread-1043-1-1.html
一. php配置
查看設定檔的路徑 /usr/local/php/bin/php -i |grep -i config
vi /usr/locall/php/etc/php.ini
尋找/disable_function
1. 配置disable_function
disable_functions = eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close
禁止這些函數,禁止駭客用這些駭客訪問
2. 配置error_log
display_error=off 這裡如果是on 有助於我們去排錯和調試========
log_errors=on
error_log=/usr/local/php/logs/php_errors.log 這裡寫絕對路徑,建立logs目錄,許可權777
error_reporting = E_ALL & ~E_NOTICE 錯誤層級
查看網站出錯的狀態代碼
curl -I -x127.0.0.1:80 http://www.111.com/forum.php
錯誤層級參考 http://www.aminglinux.com/bbs/thread-6973-1-1.html
3. 配置open_basedir 限定訪問目錄
open_basedir = /data/www1:/tmp 在php.ini裡面配置,一種方法,指定到別的目錄去,就訪問不了了
php_admin_value open_basedir "/data/www1:/tmp" 在虛擬機器主機配置,二種方法,
> /usr/local/php_errors.log 清空日誌的意思
4. 安裝php的擴充模組(memcache)
http://www.aminglinux.com/bbs/thread-45-1-1.html
源碼包的模組
cd /usr/local/src/php-5.3.28/ext/
如果想要用哪些模組,就進入到模組 執行這個命令
ext]# cd ftp
[[email protected] ftp]#/usr/local/php/bin/phpize
需要安裝autoconf yum install autoconf
然後再執行一下命令/usr/local/php/bin/phpize
ls
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install 這時告訴你這個動態模組在哪裡
ls + 模組路徑
出現 ftp.so
/usr/local/php/bin/php -i |grep -i extension_dir
vi /usr/local/php/etc/php.ini 配置加上ftp模組,需要手動加
進去加上 extension=ftp.so extension這裡說明是一個動態載入
然後 /usr/local/php/bin/php -m |grep ftp 就多了ftp這個模組了
二. mysql配置
mysql調優: http://www.aminglinux.com/bbs/thread-5758-1-1.html
/etc/my.cnf 已經拷貝了這個模板
[mysqld]
socket = /tmp/mysql.sock # 為MySQL客戶程式與伺服器之間的本地通訊指定一個通訊端檔案(Linux下預設是/var/lib/mysql/mysql.sock檔案)等我寫完後你再讀
port = 3306 # 指定MsSQL偵聽的連接埠
key_buffer = 384M # key_buffer是用於索引塊的緩衝區大小,增加它可得到更好處理的索引(對所有讀和多重寫)。索引被所有的線程共用,key_buffer的大小視記憶體大小而定。
table_cache = 512 # 為所有線程開啟表的數量。增加該值能增加mysqld要求的檔案描述符的數量。可以避免頻繁的開啟資料表產生的開銷
sort_buffer_size = 2M # 每個需要進行排序的線程分配該大小的一個緩衝區。增加這值加速ORDER BY或GROUP BY操作。
注意:該參數對應的分配記憶體是每串連獨佔!如果有100個串連,那麼實際分配的總共排序緩衝區大小為100×6=600MB
read_buffer_size = 2M # 讀查詢操作所能使用的緩衝區大小。和sort_buffer_size一樣,該參數對應的分配記憶體也是每串連獨享。=====
query_cache_size = 32M # 指定MySQL查詢結果緩衝區的大小
read_rnd_buffer_size = 8M # 改參數在使用行指標排序之後,隨機讀用的。
myisam_sort_buffer_size =64M # MyISAM表發生變化時重新排序所需的緩衝
thread_concurrency = 8 # 最大並發線程數,取值為伺服器邏輯CPU數量×2,如果CPU支援H.T超執行緒,再×2
thread_cache = 8 # #緩衝可重用的線程數
skip-locking # 避免MySQL的外部鎖定,減少出錯幾率增強穩定性。 wait_timeout = 8 # 表示閒置連線逾時時間,預設是28800s,這個參數是和interactive_timeout一起使用的,也就是說要想讓wait_timeout 生效,必須同時設定interactive_timeout
interactive_timeout = 8
long_query_time = 1 ##慢查詢日誌的逾時時間
log_slow_queries = /path/to/slow_queries ## 慢查詢日誌路徑,必須配合上面的參數一同使用
============
查看key_reads / key_read_requests 這兩的值
登入mysql
SHOW STATUS LIKE ‘key_read%‘;
--------
show varables like ‘table%‘
apache 限制指定user_agent http://www.lishiming.net/thread-1033-1-1.html
開啟虛擬機器主機設定檔
判斷是用什麼搜尋引擎
有些user_agent 不是我們想要的,可以通過rewrite功能針對 %{HTTP_USER_AGENT} 來rewirete到404頁,從而達到限制某些user_agent的請求。
配置如下
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^.*curl.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*bot.* [NC]
RewriteCond %{REQUEST_URI} !^/404*
RewriteRule .* /404.html
</IfModule>
測試curl -xlocalhost:80 www.111.com -I 跳到了404
curl -A "sfjslkfjlsjgssfhsl "-xlocalhost:80 www.111.com -I 這個就不是404了
curl -A "botslkfjlsjgssfhsl "-xlocalhost:80 www.111.com -I 這個是404 因為包含了bot
請注意,你的404.html千萬別再跳轉到其他頁面了,否則很有可能就會死迴圈了。
其實rewrite到404.html 並不是很好的辦法,而apache的rewrite功能有一項就是forbidden ,那就是 F
配置如下
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^.*curl.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*bot.* [NC]
RewriteRule .* - [F]
</IfModule>
======================
apache 限制某些目錄不能訪問通過rewrite實現 http://www.lishiming.net/thread-3587-1-1.html
deny allow肯定是可以實現的,但是這個必須指定準確的目錄,如果有很多個目錄,但是都包含某個名字,比如
bbs.1.com/1/tmp/123.html
bbs.1.com/2/tmp/123.html
bbs.1.com/3/1/2/tmp/123.html
……
如果有很多,需要逐一去定義Directory 模組,這顯然很麻煩,使用rewrite模組的 REQUEST_URI 就可以很容易實現。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^.*/data/* [NC] #data這個目錄下的都訪問不了
RewriteRule .* - [F]
</IfModule>
訪問一下網站,看到很多東西沒有出來,按下12,會看到有的檔案是403就是限制了這個目錄下面的檔案了
======================
apache rewrite 出現死迴圈 http://www.lishiming.net/thread-1043-1-1.html
我的一條規則
RewriteRule ^.* /beian.html [R,L]
複製代碼
使用curl測試,沒有問題,但是使用瀏覽器訪問時,出現了無限迴圈。
本來訪問的是 www.111.com 結果變成了 www.111.com/111/111/111/.....
雖然在最後加了 [L] 依然不管用,可能apache還是不夠智能,一直滿足條件就一直去匹配,一直去跳轉。最後沒招了只能再加一個條件。
RewriteCond %{REQUEST_URI} !^/beian.html [NC]
RewriteRule ^.* /beian.html [R,L]
這樣就不再迴圈了。
第三部分php配置和mysql配置