Apache 配置 之 禁止解析

來源:互聯網
上載者:User

標籤:禁止解析php

Apache 啟動並執行使用者是 daemon

[[email protected] ~]# ls /data/www

abc        api.php   connect.php      data         group.php  install     plugin.php  search.php  template   userapp.php

admin.php  archiver  cp.php           favicon.ico  home.php   member.php  portal.php  source      uc_client

api        config    crossdomain.xml  forum.php    index.php  misc.php    robots.txt  static      uc_server

[[email protected] ~]# ls -l /data/www/data/

total 56

drwxr-xr-x  2 daemon root   4096 Sep 25 22:42 addonmd5

drwxr-xr-x 11 daemon root   4096 Sep 25 22:42 attachment

drwxr-xr-x  2 daemon root   4096 Sep 25 22:42 avatar

drwxr-xr-x  2 daemon root   4096 May 31 11:08 backup_98143a

drwxr-xr-x  2 daemon root   4096 Sep 27 06:02 cache

drwxr-xr-x  3 daemon daemon 4096 Sep 26 00:00 diy

drwxr-xr-x  2 daemon root   4096 Sep 25 22:42 download

-rw-r--r--  1 daemon root      0 May 31 11:08 index.htm

-rw-r--r--  1 daemon daemon    0 Sep 26 00:01 install.lock

drwxr-xr-x  2 daemon root   4096 May 31 11:08 ipdata

drwxr-xr-x  2 daemon root   4096 Sep 25 22:42 log

drwxr-xr-x  2 daemon root   4096 Sep 25 22:42 plugindata

-rw-r--r--  1 daemon daemon    0 Sep 27 17:26 sendmail.lock

-rw-r--r--  1 daemon root    772 May 31 11:08 stat_setting.xml

drwxr-xr-x  2 daemon daemon 4096 Sep 26 00:00 sysdata

drwxr-xr-x  2 daemon root   4096 Sep 27 06:32 template

drwxr-xr-x  2 daemon root   4096 Sep 26 00:00 threadcache


在www.test.com 上發一個測試文章。



650) this.width=650;" src="http://s4.51cto.com/wyfs02/M02/88/34/wKiom1frgtOTAYu9AAGtF_-z32g205.jpg-wh_500x0-wm_3-wmp_4-s_4089971928.jpg" title="dis19.jpg" alt="wKiom1frgtOTAYu9AAGtF_-z32g205.jpg-wh_50" />

在網站的根目錄下


[[email protected] ~]# cd /data/www/data/attachment/forum/

[[email protected] forum]# ls

201609

[[email protected] forum]# cd 201609/

[[email protected] 201609]# ls

27  index.html

[[email protected] 201609]# cd 27

[[email protected] 27]# ls

222413qz6ng667thihgi65.jpg  index.html


222413qz6ng667thihgi65.jpg  這就是剛才發測試帖的圖片


通過IE 可以訪問到剛剛在論壇裡的那種圖片。

http://www.test.com/data/attachment/forum/201609/27/222413qz6ng667thihgi65.jpg


如果網站有漏洞,被駭客上傳病毒,不小心被執行。不可以禁止所有的使用者去上傳,但是我們可針對data 這個目錄來做限制。


[[email protected] 27]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf

       <Directory /data/www/data>

          php admin flag engine off  #關掉php 的解析引擎

         # <filesmatch "(.*)php">

         # Order deny,all

         #  Deny from all

         #  Allow from 127.0.01

        </Directory>

訪問http://www.test.com/data/info.php

你會發現會把這個 info.php 檔案下載下來,這個肯定是不行的,也是不對的。


650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/88/46/wKioL1ftNsSBAr7RAAFtcXN0u-M475.jpg" title="dis20.jpg" alt="wKioL1ftNsSBAr7RAAFtcXN0u-M475.jpg" />


如果關掉禁止解析

[[email protected] 27]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf

       <Directory /data/www/data>

          #php admin flag engine off  #關掉php 的解析引擎

         # <filesmatch "(.*)php">

         # Order deny,allow

         #  Deny from all

         #  Allow from 127.0.0.1

           </filesmatch>

        </Directory>

[[email protected] data]# apachectl -t

Syntax OK

[[email protected] data]# apachectl restart

再重新訪問http://www.test.com/data/info.php,會看到相關重要的資訊

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M00/88/46/wKioL1ftOBezO4CkAALSKxsquX8058.jpg" title="dis21.jpg" alt="wKioL1ftOBezO4CkAALSKxsquX8058.jpg" />

所以有必要做對這個目錄做一個限制

 <Directory /data/www/data>

          php admin flag engine off  #關掉php 的解析引擎

          <filesmatch "(.*)php">

          Order deny,allow

          Deny from all

          Allow from 127.0.0.1

           </filesmatch>

        </Directory>

[[email protected] data]# apachectl -t

Syntax OK

[[email protected] data]# apachectl restart

再重新訪問http://www.test.com/data/info.php,403

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/88/49/wKiom1ftOVPTO0QoAAEZwZqyMGA534.jpg" title="dis22.jpg" alt="wKiom1ftOVPTO0QoAAEZwZqyMGA534.jpg" />

再次用 curl 命 令也解析不出來

[[email protected] data]# curl -x127.0.0.1:80 www.test.com/data/info.php

<?php

phpinfo();

?>


本文出自 “CBO#Boy_Linux之路” 部落格,請務必保留此出處http://20151213start.blog.51cto.com/9472657/1857968

Apache 配置 之 禁止解析

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.