Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I recently moved from Apache Mod_wsgi to Nginx, and I have seen a major improvement on speed a lowering on memory usage and I am generally very happy with the it.

I am not a server expert, so please be gentle.

I am wondering if there are any small configuration that I might have missed, that will cause me some issues in the long run...

Please see my nginx.conf file

user  nginx nginx;

worker_processes  4;

error_log /var/log/nginx/error_log info;

events {
    worker_connections  1024;
    use epoll;
}

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

    log_format main
            '$remote_addr - $remote_user [$time_local] '
            '"$request" $status $bytes_sent '
            '"$http_referer" "$http_user_agent" '
            '"$gzip_ratio"';

    client_header_timeout   10m;
    client_body_timeout     10m;
    send_timeout            10m;

    connection_pool_size            256;
    client_header_buffer_size       1k;
    large_client_header_buffers     4 2k;
    request_pool_size               4k;

    gzip on;
    gzip_min_length 1100;
    gzip_buffers    4 8k;
    gzip_types      text/plain;

    output_buffers  1 32k;
    postpone_output 1460;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;

    keepalive_timeout       75 20;

    ignore_invalid_headers  on;
    index index.html;

    server {
            listen 80;
            server_name localhost;
            location /media/  {
                    root /www/django_test1/myapp; # Notice this is the /media folder that we create above
            }
            location /mediaadmin/  {
                    alias /opt/python2.6/lib/python2.6/site-packages/django/contrib/admin/media/; # Notice this is the /media folder that we create above
            }
            location / {
                    # host and port to fastcgi server
                    fastcgi_pass 127.0.0.1:8080;
                    fastcgi_param  SERVER_ADDR        $server_addr;
                    fastcgi_param  SERVER_PORT        $server_port;
                    fastcgi_param  SERVER_NAME        $server_name;
                    fastcgi_param  SERVER_PROTOCOL    $server_protocol;
                    fastcgi_param  PATH_INFO          $fastcgi_script_name;
                    fastcgi_param  REQUEST_METHOD     $request_method;
                    fastcgi_param  QUERY_STRING       $query_string;
                    fastcgi_param  CONTENT_TYPE       $content_type;
                    fastcgi_param  CONTENT_LENGTH     $content_length;
                    fastcgi_pass_header Authorization;
                    fastcgi_intercept_errors off;
                    client_max_body_size 100M;
                    }
            access_log      /var/log/nginx/localhost.access_log main;
            error_log       /var/log/nginx/localhost.error_log;
    }
}
share|improve this question
    
A quick Google search: wiki.nginx.org/Configuration#Full_examples brainspl.at/nginx.conf.txt and many more. –  sam Nov 21 '11 at 9:59
    
And any more context? Will this be running on your laptop or a 32 core server? How many hits are you expecting? How much bandwidth? Do you have/need failover/redundancy? Is the server doing anything else? –  sam Nov 21 '11 at 10:01
    
You probably want to specify a root directive outside of the location blocks, within your server block. Especially for FastCGI, this is a common cause of scripts not being found by the server. Also, server_name localhost is a bit unusual, but I presume it is for a test server. –  cyberx86 Nov 21 '11 at 12:31
add comment

1 Answer

I recommend you to set lower keepalive timeout, 75 is too much and practically useless. I usually use 10-20 seconds, that should be enough. But if you don't expect a lot of requests, 75 is okay too.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.