技术解析
目前使用是正常的,但是我已经搞不清楚 location 到底是干啥的了
limit_req 写在外面,使用完全没有问题,所有页面都能限制
禁止指定 UA 及 UA 为空的访问的 if 却不能写外面,只能 /和 php 各写一个,如果只写 /那就只能首页限制,其他页面照样访问
nginx -t 没有报错
但是逻辑有没有问题?判断顺序对吗
server {
listen 80;
server_name www.tntsec.com;
#设置只是用 https
#add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
#记录日志,限制缓存为 1M
access_log /var/log/nginx/log/tntsec.log main buffer=1m;
#主目录
root /var/www/html/tntsec;
#index
index index.php index.html index.htm;
#系统负载控制
sysguard on;
sysguard_load load=10 action=/highloa国外服务器d.html;
#限制并发,白名单
limit_req_whitelist geo_var_name=white_ip geo_var_value=1;
#限制并发
limit_req zone=one burst=5 forbid_action=/nocc.html;
limit_req zone=two forbid_action=/nocc.html;
limit_req zone=three burst=5 forbid_action=/nocc.html;
#屏蔽指定 IP
#deny 1.1.1.1;
#伪静态
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php$1 last;
}
location / {
#禁止指定 UA 及 UA 为空的访问
if ($http_user_agent ~ "FeedDemon|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|YisouSpider|HttpClient|MJ12bot|heritrix|EasouSpider|Ezooms|^$" ) {
access_log off;
return 403;
}
#判断是不是使用代理访问,使用 CDN 请勿开启
#if ($http_x_real_ip != $http_x_forwarded_for){
# access_log off;
# return 403;
# }
#禁止非 GET|HEAD|POST 方式的抓取
if ($request_method !~ ^(GET|HEAD|POST)$) {
access_log off;
return 403;
}
}
location ~ .*\.(css|js|ico|png)(.*) {
expires 30d;
}
# error_page 404 /404.html;
# error_page 500 502 503 504 = /500.html;
location ~ ^/admin/ {
deny all;
}
location ~ /(usr/uploads|usr/plugins/CommentToMail/cache|usr/plugins/Sitemap/sitemap|usr/plugins/CommentToMail/log)/.*\.(php|php5)?$
{
deny all;
}
location ~ .*\.php(\/.*)*$ {
#fastcgi_pass 127.0.0.1:9000;
#location ~ [^/]\.php(/|$) {
if ($http_user_agent ~ "FeedDemon|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|YisouSpider|HttpClient|MJ12bot|heritrix|EasouSpider|Ezooms|^$" ) {
access_log off;
return 403;
}
if ($request_method !~ ^(GET|HEAD|POST)$) {
access_log off;
return 403;
}
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/dev/shm/fpm-cgi.sock;
#fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PHP_VALUE "open_basedir=$document_root:/tmp/:/proc/";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}