首頁  >  文章  >  後端開發  >  nginx禁止目錄執行php的方法

nginx禁止目錄執行php的方法

藏色散人
藏色散人原創
2020-07-31 10:20:383288瀏覽

nginx禁止目錄執行php的方法:先找到並開啟「nginx.conf」設定檔;然後設定禁止單目錄以及多目錄;最後透過「service nginx restart」重啟nginx即可。

nginx禁止目錄執行php的方法

推薦:《PHP影片教學

nginx禁止目錄執行php程式

  為了安全起見,我們一般會對上傳目錄禁止執行php腳本

  修改nginx.conf設定檔

#  禁止單目錄:

location ~* ^/attachments/.*.(php|php5)$ {
  deny all;
  }

  禁止多目錄:

location ~* ^/(attachments|upload)/.*.(php|php5)$ {
  deny all;
  }

  需要注意兩點:

  1、以上的設定檔程式碼需要放到location ~ .php{...}上面,如果放到下面是無效的

  2、attachments需要寫相對路徑,不能寫絕對路徑

  3、不要忘記重啟nginx呀,service nginx restart

以上是nginx禁止目錄執行php的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn