Nginx anti-hotlink and Nginx access control and Nginx parsing php configuration

不言
Release: 2023-03-25 12:36:01
Original
1486 people have browsed it

This article mainly introduces relevant information about Nginx anti-leeching and Nginx access control and Nginx parsing PHP configuration. Here are examples to help you learn and understand this part of the content. Friends in need can refer to it

Detailed explanation of the configuration of Nginx anti-hotlinking, Nginx access control and Nginx parsing php

Nginx anti-hotlinking

The configuration is as follows, which can be compared with the above configuration Combined

location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$
{
  expires 7d;
  valid_referers none blocked server_names *.test.com ;
  if ($invalid_referer) {
    return 403;
  }
  access_log off;
}
Copy after login

Nginx access control

Requirements: Only certain users are allowed to access the /admin/ directory. IP access.

Configure as follows:

location /admin/
{
  allow 192.168.133.1;
  allow 127.0.0.1;
  deny all;
}
Copy after login

Create test

mkdir /data/wwwroot/test.com/admin/
echo “test,test”>/data/wwwroot/test.com/admin/1.html
Copy after login

Detect restart

/usr/local/nginx/bin/nginx -t && -s reload
Copy after login

Test

 curl -x127.0.0.1:80 test.com/admin/1.html -I
 curl -x192.168.133.130:80 test.com/admin/1.html -I
Copy after login

Nginx Access Control

Configuration is as follows:

  location ~ .*(abc|image)/.*\.php$
{
    deny all;
}
Copy after login

According to user_agent restriction

if ($http_user_agent ~ 'Spider/3.0|YoudaoBot|Tomato')
{
   return 403;
}
Copy after login

deny all and Return 403 has the same effect

Nginx parsing php configuration

The configuration is as follows:

location ~ \.php$
  {
    include fastcgi_params;
    fastcgi_pass unix:/tmp/php-fcgi.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
  }
Copy after login

fastcgi_pass is used to specify the address or socket that php-fpm monitors

Related recommendations:

Add the requested response log to the nginx log

The above is the detailed content of Nginx anti-hotlink and Nginx access control and Nginx parsing php configuration. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template