Ограничение частых запросов

Vvedensky nginx-forum на forum.nginx.org
Вт Янв 17 17:49:06 UTC 2017


Здравствуйте.
Вот конфигурационный файл nginx:
server {
	server_name site.ru;
	listen 12.345.67.890:80;

	charset UTF-8;
	disable_symlinks if_not_owner from=$root_path;

	index index.html index.php;
	root $root_path;
	set $root_path /var/www/site1/data/www/site.ru;
	include /etc/nginx/vhosts-includes/*.conf;
	client_max_body_size 64M;

	location ^~ /core/ {
	        try_files	error-404 @modx;
	}

    	location ^~ /config.core.php {
    		try_files	error-404 @modx;
	}

    	location ~*
^.+\.(css|js|svg|jpg|jpeg|gif|png|ico|zip|rar|doc|xls|pdf|exe|wav|bmp|rtf)$
{
		client_max_body_size 128M;
		access_log off;
		expires 7d;
		break;
	}

	location / {
		try_files $uri $uri/ @modx;
		location ~ [^/]\.ph(p\d*|tml)$ {
			try_files /does_not_exists @php;
		}
	}

	location @modx {
		limit_req zone=one burst=3;
		rewrite ^/(.*)$ /index.php?q=$1&$args;
	}

	location @php {
		fastcgi_index index.php;
		fastcgi_buffers 8 16k;
		fastcgi_pass unix:/var/www/php-fpm/site1.sock;
		fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
		try_files $uri @modx;
		include fastcgi_params;
	}
}
Есть следующая проблема: при нахождении файла в корневой директории его
нужно обрабатывать по правилу location @modx и затем через fastcgi (это
может быть как файл с расширением php, так и файл без расширения), частые
запросы нужно ограничить. Если файл находится в папках /assets, /manager,
/connectors и имеет расширение php, то его также нужно пропустить через
fastcgi, при этом частота запросов к нему не должна быть ограничена. Не
пойму как правильно составить правила обработки. Можете ли посоветовать
какой-либо вариант?

Posted at Nginx Forum: https://forum.nginx.org/read.php?21,272030,272030#msg-272030



Подробная информация о списке рассылки nginx-ru