php-fpm优化
關(guān)閉危險(xiǎn)參數(shù)
1、打開php的安全模式
php的安全模式是個(gè)非常重要的php內(nèi)嵌的安全機(jī)制,能夠控制一些php中的函數(shù)執(zhí)行,比如system(),同時(shí)把被很多文件操作的函數(shù)進(jìn)行了權(quán)限控制。
默認(rèn)關(guān)閉,338行
safe_mode = Off
改為
safe_mode = On
2、用戶組安全
; By default, Safe Mode does a UID compare check when
; opening files. If you want to relax this to a GID compare,
; then turn on safe_mode_gid.
; http://php.net/safe-mode-gid
safe_mode_gid = Off # php5.3.27默認(rèn)關(guān)閉
3、關(guān)閉危險(xiǎn)函數(shù)
當(dāng)打開安全模式,函數(shù)禁止可以不做,但為了雙重保險(xiǎn)還是做。比如不執(zhí)行system()能執(zhí)行系統(tǒng)命令的函數(shù),或能查看php信息的phpinfo()等函數(shù)。方法如下
disable_functions = system,passthru,exec,shell_exec,popen,phpinfo
4、關(guān)閉php版本號
php版本號會(huì)在http的head里顯示
expose_php = On
改為
expose_php = Off
5、關(guān)閉注冊全局變量
register_globals = Off # 默認(rèn)關(guān)閉,不要打開
6、打開magic_quotes_gpc防止SQL注入
magic_quotes_gpc = Off
改為
magic_quotes_gpc = On
7、錯(cuò)誤信息控制
一般php在沒有連接到數(shù)據(jù)庫或者其他情況下會(huì)有錯(cuò)誤提示,一般錯(cuò)誤信息中會(huì)包含php腳本當(dāng)前的路徑信息或者查詢的SQL語句等信息,這類信息在生產(chǎn)環(huán)境是不允許的,應(yīng)禁止。想要錯(cuò)誤信息,應(yīng)該導(dǎo)入日志。
display_errors = Off (默認(rèn)值,不是改為off)
顯示錯(cuò)誤級別
error_reporting = E_WARNING & E_ERROR
8、錯(cuò)誤日志
log_errors = On
log_errors_max_len = 1024 # Set maximum length of log_errors.
error_log = /app/logs/php_errors.log # 注意寫權(quán)限
9、資源參數(shù)限制優(yōu)化
# 設(shè)置每個(gè)腳本運(yùn)行的最長時(shí)間,當(dāng)無法上傳較大的文件或者后臺備份數(shù)據(jù)經(jīng)常超時(shí),需調(diào)整下面參數(shù),單位秒。
max_execution_time = 30
# 每個(gè)腳本使用的最大內(nèi)存
memory_limit = 128M
# 每個(gè)腳本等待輸入數(shù)據(jù)最長時(shí)間
max_input_time = 60
# 上傳文件的最大許可
upload_max_filesize = 2M
10、安全參數(shù)優(yōu)化
# 禁止打開遠(yuǎn)程地址
allow_url_fopen = On
改為
allow_url_fopen = Off
# 防止Nginx文件類型錯(cuò)誤解析漏洞
cgi.fix_pathinfo=0
原地址:http://lidao.blog.51cto.com/3388056/1953307
轉(zhuǎn)載于:https://www.cnblogs.com/jmaly/p/7383479.html
總結(jié)
- 上一篇: 做好数据挖掘模型的9条经验总结
- 下一篇: php验证码--图片