search
HomeBackend DevelopmentPHP ProblemHow to prohibit directory execution of php in nginx

How to prohibit directory execution of php in nginx: first find and open the "nginx.conf" configuration file; then set the prohibition of single directory and multiple directories; finally restart nginx through "service nginx restart".

How to prohibit directory execution of php in nginx

Recommended: "PHP Video Tutorial"

nginx prohibits directory execution PHP program

For security reasons, we generally prohibit running php scripts in the upload directory

Modify the nginx.conf configuration file

Disable single directory:

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

Multiple directories are prohibited:

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

Two points need to be noted:

1. The above configuration file code needs to be placed above location ~ .php{...}. If placed The following is invalid

2. Attachments need to write relative paths, not absolute paths

3. Don’t forget to restart nginx, service nginx restart

The above is the detailed content of How to prohibit directory execution of php in nginx. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment