Disable HEAD + Good config for large files?

bartbant nginx-forum at nginx.us
Mon Dec 5 12:39:27 UTC 2011

Hi everyone!

Over the past weeks I read a lot on your pages and blogs on the net but
I still have some questions left that seem to be unanswered until now.

My site is acting like some kind of proxy and transfers big files (up to
several GB) from a remote site to the user. What the script actually
does is read 4096 byte, write what was read and flush the buffer. Then
start over till remote file is read completely.

Code is written in php. I previously used Apache to do the work but
nginx performs much better in any case. However, when using HEAD instead
of GET with Apache I recognized that even though the custom header is
already flush()ed by the php script Apache will not release the file
until the php script ended. With this only a few head requests will
congest the incoming bandwidth of the server.

For Apache I found this solution:
                RewriteEngine on
                RewriteCond %{REQUEST_METHOD}
                RewriteRule .* - [F,L]

Is nginx behaving the same as Apache did before?

How would the config for apache look like in nginx? (As the code above
is not mine and I'm not good at rewrite rules, please provide me an
example or where to look.)

For the same project I also recognized that the servers speed will drop
a bit for every user once I reach about 150 - 200 connections (according
to nginx status). The servers are doing around 30 - 50 MByte/s in and
out (so 60 - 100 MByte/s in total) on gigabit lines and even on 10
gigabit lines. The thing is, that munin (monitoring tool) shows me about
6k to 8k interrupts on eth0 for the time speeds are not as they should
be. I tried several server providers and most servers look the same or
even worse. So... who to blame? All server provider lines are bad? Too
many interrupts for eth0? Wrong nginx config?

I'm running nginx 1.0.10 (latest stable) and php-fpm on ubuntu 10.04
server edition.

user www-data;
worker_processes 6; #6 cores cpu used in this case
pid /var/run/nginx.pid;

events {
        worker_connections 256;

http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 0;
        types_hash_max_size 2048;
        server_tokens off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        gzip off;

server {
        index  index.php;

        server_name some.servername.com;

        access_log  /var/log/nginx/localhost.access.log;

        location / {
                root   /var/www;
                index  index.php;

        location /nginx_status {
                stub_status on;
                access_log   off;
                deny all;

        ## Disable viewing certain directorys
        location ~ /(dir1|dir2|dir3) {
               deny  all;
               return 404;

        ## Images and static content is treated different
        location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
                root   /var/www;
                access_log        off;
                expires           30d;
        ## Parse all .php file in the /var/www directory
        location ~ .php$ {
                root   /var/www;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_pass   backend;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME 
                include fastcgi_params;
                fastcgi_param  QUERY_STRING     $query_string;
                fastcgi_param  REQUEST_METHOD   $request_method;
                fastcgi_param  CONTENT_TYPE     $content_type;
                fastcgi_param  CONTENT_LENGTH   $content_length;
                fastcgi_intercept_errors        on;
                fastcgi_ignore_client_abort     off;
                fastcgi_connect_timeout 60;
                fastcgi_send_timeout 180;
                fastcgi_read_timeout 180;
                fastcgi_buffer_size 4k;
                fastcgi_buffers 8 64k;
                fastcgi_busy_buffers_size 256k;
                #fastcgi_temp_file_write_size 256k;
                fastcgi_max_temp_file_size 0;

        ## Disable viewing .htaccess & .htpassword
        location ~ /\.ht {
               deny  all;
               return 404;

upstream backend {

If I forgot 
I would be glad for any advice and help.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,219630,219630#msg-219630

More information about the nginx mailing list