How to ban access to php in nginx
nginx禁止访问php的方法:1、配置nginx,禁止解析指定目录下的指定程序;2、将“location ~^/images/.*\.(php|php5|sh|pl|py)${deny all...}”语句放置在server标签内即可。
本教程操作环境:Windows7系统、PHP8.1版、Dell G3电脑。
nginx怎么禁止访问php?
nginx站点目录及文件URL访问控制
一、根据扩展名限制程序和文件访问
利用nginx配置禁止访问上传资源目录下的PHP、Shell、Perl、Python程序文件。
配置nginx,禁止解析指定目录下的指定程序。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
对上述目录的限制必须写在nginx处理PHP服务配置的前面,如下:
放置在server标签内:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
nginx下配置禁止访问*.txt和*.doc文件
配置如下:
放置在server标签内:
1 2 3 4 5 6 7 8 9 10 11 |
|
二、禁止访问指定目录下的所有文件和目录
配置禁止党文指定的单个或多个目录。
禁止访问单个目录的命令如下:
放置在server标签内:
1 2 3 4 5 6 7 |
|
禁止访问多个目录的配置如下:
1 2 3 |
|
禁止访问目录并返回指定的http状态码,配置如下:
放置在server标签内:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
作用:禁止访问目录下的指定文件或者禁止访问指定目录下的所有内容。
三、限制网站来源IP访问
禁止目录让外界访问,但允许某IP访问该目录且支持PHP解析,配置如下:
在server标签内配置如下:
1 2 3 4 5 6 7 8 9 10 11 |
|
说明:该配置只允许192.168.0.4IP访问mysql_loging目录
限制IP或IP段访问,配置如下:
添加在server标签内:
1 2 3 4 5 6 |
|
说明:此限制是对某些IP做整个网站的限制访问。
nginx做反向代理的时候也可以限制客户端IP,具体如下:
方法1:使用if来控制,配置如下:
1 2 3 4 5 6 7 |
|
方法2:利用deny和allow只允许IP访问,配置如下:
1 2 3 4 5 6 |
|
方法3:只拒绝某些IP访问,配置如下:
1 2 3 4 5 6 |
|
注意事项:
deny一定要加一个IP,否者会直接跳转到403,不在往下执行了,如果403默认页在同一域名下,会造成死循环访问。
对于allow的IP段,从允许访问的段位从小到大排列,如127.0.0.0/24的下面才能是10.10.0.0/16,其中:
24表示子网掩码:255.255.255.0
16表示子网掩码:255.255.0.0
8表示子网掩码:255.0.0.0
以deny all; 结尾,表示除了上面允许的,其他的都禁止。如:
1 2 3 4 5 |
|
四、配置nginx,禁止非法域名解析访问企业网站
方法1:让使用IP访问网站的用户,或恶意接卸域名的用户,收到501错误,配置如下:
1 2 3 4 5 |
|
方法2:通过301跳转主页,配置如下:
1 2 3 4 5 |
|
方法3:发现某域名恶意解析到公司的服务器IP,在server标签里添加以下代码即可,若有多个server要多处添加。
1 2 3 |
|
推荐学习:《PHP视频教程》
The above is the detailed content of How to ban access to php in nginx. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.
