一個公共的能夠上傳圖片的目錄下,應該給該目錄作php禁止解析,這樣就會防止其它人上傳php的***。php
[root@chy ~]# vi /usr/local/apache2.4/conf/extra/httpd-vhosts.conf <Directory /data/wwwroot/111.com/upload> php_admin_flag engine off <FilesMatch (.*)\.php(.*)> Order allow,deny Deny from all </FilesMatch> </Directory> 主要配置如上,配置詳解 <Directory /data/wwwroot/111.com/upload>(給111.com下面的upload目錄作禁止php解析 php_admin_flag engine off(禁止php解析) <FilesMatch (.*)\.php(.*)>(通配全部的php) Order allow,deny Deny from all(拒絕全部的php) </FilesMatch> </Directory>(這裏作filesmatch (deny)是由於不deny php會訪問源代碼) [root@chy ~]# /usr/local/apache2.4/bin/apachectl -t Syntax OK [root@chy ~]# /usr/local/apache2.4/bin/apachectl graceful (查看下配置是否有問題,而後加載配置)
測試php解析html
[root@chy 111.com]# mkdir /data/wwwroot/111.com/upload (建立一個php目錄) [root@chy 111.com]# ls 123.php admin index.php lf.png upload [root@chy 111.com]# cp 123.php upload/ (將123.phpcp到upload目錄下) [root@chy 111.com]# curl -x192.168.212.10:80 'http://www.111.com/upload/123.php' -I HTTP/1.1 403 Forbidden Date: Thu, 03 Aug 2017 21:57:03 GMT Server: Apache/2.4.27 (Unix) PHP/5.6.30 Content-Type: text/html; charset=iso-8859-1 [root@chy 111.com]# curl -x192.168.212.10:80 'http://www.111.com/upload/123.php' <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access /upload/123.php on this server.<br /> </p> </body></html> (如上這兩的測試是 <FilesMatch (.*)\.php(.*)>(通配全部的php) Order allow,deny Deny from all(拒絕全部的php) </FilesMatch> </Directory>(這裏作filesmatch (deny)是由於不deny php會訪問源代碼)在不讓解析php的同時也不讓訪問源代碼的操做) [root@chy 111.com]# curl -x192.168.212.10:80 'http://www.111.com/upload/123.php' <?php echo "chyloveff"; php?> (通過測試當不加 <FilesMatch (.*)\.php(.*)>(通配全部的php) Order allow,deny Deny from all(拒絕全部的php) </FilesMatch> </Directory> 這步操做是會下在php的源代碼這樣來講是很是危險的)