限定目錄禁止解析php-限制user_agent-php相關配置

限定目錄禁止解析php

防止亂上傳php文件被執行php

1.修改虛擬主機配置文件:/usr/local/apache2.4/conf/extra/httpd-vhosts.confshell

<Directory /data/wwwroot/www.123.com/upload>
        php_admin_flag engine off
        <FilesMatch (.*)\.php(.*)>
        Order allow,deny
        Deny from all
        </FilesMatch>
    </Directory>

 

2.從新加載配置參數:apache

/usr/local/apache2.4/bin/apachectl -t瀏覽器

/usr/local/apache2.4/bin/apachectl gracefulbash

 

3.建立測試php文件:php7

 

4.測試:curl

以上是1中全代碼的運行結果;不能訪問,更不能解析socket

 

以上是單「php_admin_flag engine off」代碼的運行結果,不能解析。函數

 

限制user_agent:

user_agent能夠理解爲瀏覽器標識測試

1.修改虛擬主機配置文件:/usr/local/apache2.4/conf/extra/httpd-vhosts.conf

<IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{HTTP_USER_AGENT}  .*curl.* [NC,OR]
        RewriteCond %{HTTP_USER_AGENT}  .*baidu.com.* [NC]
        RewriteRule  .*  -  [F]
    </IfModule>//NC 忽略大小寫,F爲fobidden的意思

 

2.從新加載配置參數:

/usr/local/apache2.4/bin/apachectl -t

/usr/local/apache2.4/bin/apachectl graceful

 

3.測試:

curl -A "123123" -x127.0.0.1:80 'http://111.com/123.hph'              #-A 指定user_agent,-e 指定referer 必須以「http://」開頭,-x 省略hosts,-I 僅僅查看狀態碼

 

php配置相關:

/usr/local/php/bin/php -i|grep -i "loaded configuration file"               #查看php配置文件位置 /usr/local/php7/etc/php.ini

date.timezone =                                                                                  #定義時區,date.timezone = Asia/Shanghai

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 (危險的函數)

error_log =                                                                                        #定義log路徑,即定義 log_errors 的路徑

 log_errors =                                                                                     #是否打開錯誤日誌,on打開,off開啓

error_reporting =                                                                              #定義日誌的級別,默認爲E_all,生產環境上使用E_ALL & ~E_NOTICE

display =                                                                                           #on在瀏覽器顯示錯誤信息,off關閉在瀏覽器顯示錯誤提示

open_basedir =/data/wwwroot/111.com:/tmp                                   #php.ini是針對全部站點的,此項亦能夠在虛擬主機配置文件中作配置,添加以下行: php_admin_value open_basedir "/data/wwwroot/111.com:/tmp/"

相關文章
相關標籤/搜索