proxy_temp и редкие no such file or directory

umask umask at yandex.ru
Thu Jan 15 15:08:20 MSK 2009


Добрый день,

столкнулись с такой ситуацией.

Имеем конфиг:

..
http {
	include       /etc/nginx/mime.types;
	default_type  text/plain;

	log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
			  '"$status" $body_bytes_sent "$http_referer" '
			  '"$http_user_agent" "$http_x_forwarded_for" "$http_cookie" '
			  '"$http_host" $request_time "$upstream_addr" [$upstream_response_time]';

	# use as apache httpd compat logs
	log_format compat '$remote_addr - $remote_user [$time_local] "$request" '
			  '"$status" $body_bytes_sent "$http_referer" '
			  '"$http_user_agent" "$http_x_forwarded_for"';

	access_log /var/log/nginx/access.log main;
	sendfile       on;
	tcp_nopush     on;

	# http://sysoev.ru/web/upload.html
	lingering_time     30;
	lingering_timeout  5;

	client_header_timeout  60;
	client_body_timeout    60;
	send_timeout           30;

	client_max_body_size   16m;

	large_client_header_buffers 8 32k;

	keepalive_timeout  300 240;

	reset_timedout_connection  on;

	limit_zone   merging  $binary_remote_addr  16m;

	server {
		listen 80 default backlog=1024 deferred;
		server_name .mydomain.ru .mydomain.net;

		root /srv/www/xxx/htdocs/;
		index index.php;


		if ($http_host ~* www.mydomain.ru) {
			rewrite  ^ http://mydomain.ru$request_uri? permanent;
		}

		if ($http_host ~* www.mydomain.net) {
			rewrite  ^ http://mydomain.net$request_uri? permanent;
		}


		if ($http_host !~* .*mydomain.*) {
			rewrite ^ http://mydomain.ru$request_uri? permanent;
		}

		location /admin {
                        client_body_buffer_size  256k;
			proxy_buffering off;
                        proxy_read_timeout    60;
			proxy_connect_timeout 3;
			proxy_pass   http://127.0.0.1:8080;
			proxy_set_header   X-Real-IP        $remote_addr;
			proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
			proxy_set_header   Host             $host;
		}

		location / {
                        client_body_buffer_size  256k;
                        proxy_buffers 128 64k;
                        proxy_read_timeout    60;
			proxy_connect_timeout 3;
			proxy_pass   http://127.0.0.1:8080;
			proxy_set_header   X-Real-IP        $remote_addr;
			proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
			proxy_set_header   Host             $host;
		}

		location /merge.php {
			#access_log /tmp/merge1.log main;
			root /tmp/proxy_temp;
			error_page	404 = @fetch;
		}

		location @fetch {
                        # WARNING! We set limit_conn to prevent DoS for filesystem
                        # files descriptors! Be ware!
			internal;
			access_log /tmp/merge2.log main;
                        limit_conn         merging 2;
			proxy_pass         http://127.0.0.1:8080;
			proxy_temp_path    /tmp/proxy_temp;
			proxy_store        /tmp/proxy_temp/$request_uri;
			proxy_set_header   X-Real-IP        $remote_addr;
			proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
			proxy_set_header   Host             $host;
		}

	}}


Вся суть в последних 2-х локейшинах.
Мы имеем в 1-м локейшене кэширование всего, что отдано по merge.php. Если в кэше нету запрошенного файла, то идём на бэкэнд и генерим там контект, сохраняем в кэше.
Помимо всего прочего есть limit_conn во 2-м локейшене - чтобы 
а) не долбить в бэкэнд, если будет DoS/DDoS (ибо merge.php собирает из нескольких .js один файл и это есть какие-то ресурсы).
б) не сорить очень-очень сильно в файловой системе (ясное дело, что даже с двумя параллельными запросами можно очень быстно забить ФС, но если это делать в 100 раз быстрее, то до еженочной чистки proxy_temp можно не дожить).


Всё работает по тестам отлично. Когда пришли юзеры в error-log'е стали редко появлятся вот такие сообщения:
2009/01/15 04:04:15 [error] 26040#0: *305905 open() "/tmp/proxy_temp/merge.php/--1230217985--style/analytics.css" failed (2: No such file or directory), client: 85.114.85.233, server: mydomain.ru, request: "GET /merge.php/--1230217985--style/analytics.css HTTP/1.1", host: "mydomain.ru", referrer: XXX
2009/01/15 04:04:15 [error] 26038#0: *305910 open() "/tmp/proxy_temp/merge.php/--1230217985--style/popup.css--style/styles.css--style/mc.css--style/districts.css--style/jqac.css--style/header.css--style/footer.css" failed (2: No such file or directory), client: 85.114.85.233, server: mydomain.ru, request: "GET /merge.php/--1230217985--style/popup.css--style/styles.css--style/mc.css--style/districts.css--style/jqac.css--style/header.css--style/footer.css HTTP/1.1", host: "mydomain.ru", referrer: XXX
2009/01/15 04:04:18 [error] 26040#0: *305905 open() "/tmp/proxy_temp/merge.php/--1230217985--script/jquery-uncompressed.js--script/jquery-cookie.js--script/jquery-dimensions.js--script/google-analytics.js--script/common.js--script/footer.js" failed (2: No such file or directory), client: 85.114.85.233, server: mydomain.ru, request: "GET /merge.php/--1230217985--script/jquery-uncompressed.js--script/jquery-cookie.js--script/jquery-dimensions.js--script/google-analytics.js--script/common.js--script/footer.js HTTP/1.1", host: "mydomain.ru", referrer: XXX
2009/01/15 04:04:22 [error] 26038#0: *305910 open() "/tmp/proxy_temp/merge.php/--1230217985--script/analytics.js--script/jquery-autocomplete.js" failed (2: No such file or directory), client: 85.114.85.233, server: mydomain.ru, request: "GET /merge.php/--1230217985--script/analytics.js--script/jquery-autocomplete.js HTTP/1.1", host: "mydomain.ru", referrer: XXX
2009/01/15 04:16:39 [error] 26038#0: *307425 open() "/tmp/proxy_temp/merge.php/--1230217985--style/application.css" failed (2: No such file or directory), client: 67.195.37.165, server: mydomain.ru, request: "GET /merge.php/--1230217985--style/application.css HTTP/1.0", host: "mydomain.ru", referrer: XXX
2009/01/15 05:12:42 [error] 26040#0: *322960 open() "/tmp/proxy_temp/merge.php/--1231946306--" failed (2: No such file or directory), client: 65.55.110.170, server: mydomain.ru, request: "GET /merge.php/--1231946306-- HTTP/1.0", host: "mydomain.ru", referrer: XXX
2009/01/15 05:13:36 [error] 26040#0: *322861 open() "/tmp/proxy_temp/merge.php/--1230217985--script/regform.js" failed (2: No such file or directory), client: 92.49.130.162, server: mydomain.ru, request: "GET /merge.php/--1230217985--script/regform.js HTTP/1.1", host: "mydomain.ru", referrer: XXX
2009/01/15 09:34:35 [error] 26040#0: *413426 open() "/tmp/proxy_temp/merge.php/--1230217985--style/glossary.css" failed (2: No such file or directory), client: 72.30.81.153, server: mydomain.ru, request: "GET /merge.php/--1230217985--style/glossary.css HTTP/1.0", host: "mydomain.ru", referrer: XXX
2009/01/15 09:49:54 [error] 26038#0: *417398 open() "/tmp/proxy_temp/merge.php/--1230217985--style/locations.css" failed (2: No such file or directory), client: 94.179.233.169, server: mydomain.ru, request: "GET /merge.php/--1230217985--style/locations.css HTTP/1.1", host: "mydomain.ru", referrer: XXX
2009/01/15 10:44:41 [error] 26037#0: *439024 open() "/tmp/proxy_temp/merge.php/--1230217985--style/glossary.css" failed (2: No such file or directory), client: 82.138.44.66, server: mydomain.ru, request: "GET /merge.php/--1230217985--style/glossary.css HTTP/1.0", host: "mydomain.ru", referrer: XXX
2009/01/15 10:49:42 [error] 26037#0: *440371 open() "/tmp/proxy_temp/merge.php/--1230217985--style/about.css" failed (2: No such file or directory), client: 195.16.72.182, server: mydomain.ru, request: "GET /merge.php/--1230217985--style/about.css HTTP/1.1", host: "mydomain.ru", referrer: XXX
2009/01/15 12:33:27 [error] 26037#0: *478866 open() "/tmp/proxy_temp/merge.php/--1230217985--style/media.css" failed (2: No such file or directory), client: 79.139.146.91, server: mydomain.ru, request: "GET /merge.php/--1230217985--style/media.css HTTP/1.1", host: "mydomain.ru", referrer: XXX
2009/01/15 12:33:28 [error] 26037#0: *478880 open() "/tmp/proxy_temp/merge.php/--1230217985--script/advertise.js" failed (2: No such file or directory), client: 79.139.146.91, server: mydomain.ru, request: "GET /merge.php/--1230217985--script/advertise.js HTTP/1.1", host: "mydomain.ru", referrer: XXX
2009/01/15 13:30:57 [error] 26038#0: *494361 open() "/tmp/proxy_temp/merge.php/--1230217985--style/list.css" failed (2: No such file or directory), client: 193.164.146.121, server: mydomain.ru, request: "GET /merge.php/--1230217985--style/list.css HTTP/1.0", host: "mydomain.ru", referrer: XXX
2009/01/15 13:30:57 [error] 26037#0: *494851 open() "/tmp/proxy_temp/merge.php/--1232015362--style/popup.css--style/styles.css--style/mc.css--style/districts.css--style/jqac.css--style/header.css--style/footer.css" failed (2: No such file or directory), client: 79.139.146.91, server: mydomain.ru, request: "GET /merge.php/--1232015362--style/popup.css--style/styles.css--style/mc.css--style/districts.css--style/jqac.css--style/header.css--style/footer.css HTTP/1.1", host: "mydomain.ru", referrer: XXX
2009/01/15 13:30:58 [error] 26039#0: *494755 open() "/tmp/proxy_temp/merge.php/--1232015362--style/card.css" failed (2: No such file or directory), client: 79.139.146.91, server: mydomain.ru, request: "GET /merge.php/--1232015362--style/card.css HTTP/1.1", host: "mydomain.ru", referrer: XXX
2009/01/15 13:30:58 [error] 26038#0: *494395 open() "/tmp/proxy_temp/merge.php/--1230217985--script/controls.js--script/drag.js--script/popup.js--script/map.js--script/search.js--script/tooltip.js--script/objects_counter.js--script/raphael.js--script/jquery-autocomplete.js" failed (2: No such file or directory), client: 193.164.146.121, server: mydomain.ru, request: "GET /merge.php/--1230217985--script/controls.js--script/drag.js--script/popup.js--script/map.js--script/search.js--script/tooltip.js--script/objects_counter.js--script/raphael.js--script/jquery-autocomplete.js HTTP/1.0", host: "mydomain.ru", referrer: XXX
2009/01/15 13:31:13 [error] 26040#0: *495218 open() "/tmp/proxy_temp/merge.php/--1232015363--style/index.css" failed (2: No such file or directory), client: 84.204.73.230, server: mydomain.ru, request: "GET /merge.php/--1232015363--style/index.css HTTP/1.0", host: "kp.mydomain.ru", referrer: XXX
2009/01/15 13:53:31 [error] 26037#0: *503439 open() "/tmp/proxy_temp/merge.php/--1232015367--" failed (2: No such file or directory), client: 65.55.109.145, server: mydomain.ru, request: "GET /merge.php/--1232015367-- HTTP/1.0", host: "mydomain.ru", referrer: XXX
2009/01/15 14:36:29 [error] 21587#0: *78 open() "/tmp/proxy_temp/merge.php/--1230217985--style/partnership.css" failed (2: No such file or directory), client: 87.118.195.241, server: mydomain.ru, request: "GET /merge.php/--1230217985--style/partnership.css HTTP/1.1", host: "mydomain.ru", referrer: XXX


всего 20 подобных ошибок на 170к запросов (170к - это вообще запросы на бэкэнд, а не в merge.php).

Включил уровень debug при логировании ошибок. Помимо всё тех же сообщений выше ничего дополнительного узнать не удалось.


Кто-нибудь сталкивался с таким поведением?
В чём проблема?



Спасибо.





More information about the nginx-ru mailing list