website connection reset on first load

Posted by Tar on Server Fault See other posts from Server Fault or by Tar
Published on 2012-11-12T00:00:03Z Indexed on 2012/11/12 23:03 UTC
Read the original article Hit count: 248

Filed under:
|
|

i'm using nginx with php-cgi. lately a problem has arose where if you don't view my site for a while, like 3-4 minutes, and then open it again, the first request you send will return connection reset by peer in the browser. if you refresh, operation is normal for all subsequent requests. this happens every time and it isn't just an isolated incident, it happens to everyone using my site. i've tried to restart nginx and php-cgi but to no avail. does anyone know what the problem could be? i can provide whatever information necessary.

it's worth noting that there's nothing in error log besides that message about client closing the connection early.

nginx.conf

user  nobody;
worker_processes  4;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;


events {
    worker_connections  2048;
}


http {
    include       /etc/nginx/mime.types;
    error_page 404 /404.html;
    error_page 403 /403.html;
        error_page 444 /444.html;
error_page 502 /502.html;

    default_type  application/octet-stream;

    log_format  main  '$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;
        large_client_header_buffers 8 8k;
    sendfile        on;
    tcp_nopush     on;
        tcp_nodelay on;
    keepalive_timeout  30;
        server_tokens off;

    gzip  on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 64 8k;
gzip_min_length 1024; gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    include /etc/nginx/conf.d/*.conf;
}

default.conf

server {
    listen  80;
    server_name  domain.com;
    error_log /var/log/nginx/error.log debug;   
    access_log  /var/log/nginx/access.log;


    location / {
    if ($request_method !~ ^(GET|HEAD|POST)$ ) {
        return 444;
    }

    if ($http_user_agent ~* Havij|hvj|acunetix|wget|HTtrack) {
       return 403;
    }

    root   /home/admin06/public_html;
    autoindex off;        
    index  index.php;


# Images and static content is treated different
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
      access_log        off;
      expires           30d;
      root /home/admin06/public_html;
    }

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

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
#try_files $uri =404;
    fastcgi_pass backend;


        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /home/site/public_html$fastcgi_script_name;
        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 60;
        fastcgi_read_timeout 60;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }

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

    location ~ access_log {
    deny all;
}
location ~ \.cgi {
deny all;
}

location ~ \.db {
deny all;
}
}

© Server Fault or respective owner

Related posts about nginx

Related posts about connection