server {
	# reserve 1MB under the name 'proxied' to track uploads
	listen  *:80;
	# can't use wildcards in first server_name
	server_name cs-2.local;
	client_max_body_size 10m;
# germ
		set_real_ip_from 83.133.121.41;
# amsterdam
		set_real_ip_from 109.201.141.180;
		real_ip_header     X-Real-IP;

	access_log  /var/log/nginx/cs-2.access.log;
	error_log   /var/log/nginx/cs-2.error.log;

	include /etc/nginx/opt.conf/access_list.conf;

	if ($uri ~ ^/frames/thumb/) {
	set $w 100;
        set $h 150;
        }

	if ($uri ~ ^/frames_temp/thumb) {
	set $w 100;
        set $h 150;
        }


	location / {
	    root /var/www/vhosts/cs-2/current;

		# autoindex off;
		# autoindex_exact_size on;
		# autoindex_localtime off;

		# expires off;

		# cooperate with mod_realip in apache-1.3 or mod_rpaf in apache-2.x
			proxy_redirect off;
			proxy_set_header Host $host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $remote_addr;
			proxy_pass  http://127.0.0.1:81/;
		#
		# NB: it's better for URI canonicalization that apache sits on :80
		# (even if that's only 127.0.0.1:80)
		#
		# see also set_real_ip_from, real_ip_header if this nginx
		# would need to cooperate with another one acting as a frontend
	}

location ~* /cron\.php$|/\.ht|/structure\.sql$ {
	deny  all;
	}



	location ~^/frames/thumb/.*\.(?:jpg|gif|png)$ {
	image_filter_buffer 18M;
	root /var/www/vhosts/cs-2/current/frames;
	rewrite ^/frames/thumb/(.*)$ /$1;
        image_filter resize $w $h;
        break;
        }


	location ~^/frames_temp/thumb/.*\.(?:jpg|gif|png)$ {
	image_filter_buffer 18M;
	root /var/www/vhosts/cs-2/current/frames_temp;
	rewrite ^/frames_temp/thumb/(.*)$ /$1;
        image_filter resize $w $h;
        break;
        }

#location ~* /cron\.php$|\.tpl|/\.ht|/structure\.sql$ {
#	deny  all;
#}

# Static files location
        location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|wav|bmp|rtf|js|html|iso|avi|mpg|mp3|mp4|mdf|mds|torrent)
        {
        root /var/www/vhosts/cs-2/current;
            }



	location ~ \.flv$ {
        flv;
	root /var/www/vhosts/cs-2/current;
	access_log  /var/log/nginx/cs-2_flv.access.log;
        add_header Content-Disposition 'attachment; filename=$query_string';
    }



# Upload form should be submitted to this location
    location /ajax/upload_movie {
	    client_max_body_size 10737418240;
            # Pass altered request body to this location
            upload_pass   @test;
            # Store files to this location
            upload_store /mnt/array/theon/tmp;
            # Set rights
            upload_store_access user:rw group:rw;
            
        # Set specified fields in request body
        upload_set_form_field $upload_field_name.file_name "$upload_file_name";
        upload_set_form_field $upload_field_name.content_type "$upload_content_type";
        upload_set_form_field $upload_field_name.tmp_path "$upload_tmp_path";
        # Set calculated fields
        upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";
        # Pass matching fields from client to backend
        upload_pass_form_field "^X-Progress-ID$";
        # Delete uploaded files on these backend HTTP codes
        upload_cleanup 400 404 499 500-505;
	# Размер буфера, который будет использован для записи данных на диск.
	#upload_buffer_size page-size-in-bytes
	# Указывает размер буфера, который будет использован для аккумулирования 
        # заголовка части тела запроса. Если заголовок не помещается в буфер, то 
        # запрос считается некорректным.
#        upload_max_part_header_len 5M;
        # Soft limit
        upload_max_file_size 10737418240;
        # Если тело результативного запроса превышает, то выдается 413
        upload_max_output_body_len 10737418240;
	# Speed-limit
        #upload_limit_rate 0
        # Pass GET args to backend
        upload_pass_args on;
        track_uploads proxied 60s;

upload_progress_template starting "$uploadprogress_callback({ 'state' : 'starting'});";
upload_progress_template error "$uploadprogress_callback({ 'state' : 'error', 'status' : $uploadprogress_status });";
upload_progress_template done "$uploadprogress_callback({ 'state' : 'done'});";
upload_progress_template uploading "$uploadprogress_callback({ 'state' : 'uploading', 'received' : $uploadprogress_received, 'size' : $uploadprogress_length });";

        }

        # Pass altered request body to a backend
        location @test {
        proxy_pass   http://127.0.0.1:81;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
#        track_uploads proxied 60s;

}


#        location  /ajax/upload_frames {
#        client_max_body_size 10485760;
#}


#	location ^~ /ajax/upload_movie_status {
	location /ajax/upload_movie_status {
#        track_uploads proxied 60s;
#	upload_progress_json_output;
	upload_progress_jsonp_output;
# report uploads tracked in the 'proxied' zone
        report_uploads proxied;
#        track_uploads proxied 60s;
	}


#        	charset         on;
#        	source_charset  koi8-r;

		access_log  /var/log/nginx/store.log;
}

