web-dev-qa-db-ja.com

nginx:既存の接続がリモートホストによって強制的に閉じられました

Windows Server 2008 R2でnginxを実行していますが、クラッシュしているようです。php-cgiも使用されており、php-cgiが問題の一部です。ページにいる約30秒後、php-cgiが閉じて動作を停止しますが、これはajax呼び出しで1ページのみにアクセスしたときにのみクラッシュします。ajax呼び出しがエラーの原因であるようで、nginxエラーのようですログ以下のエラーがあります

2015/09/27 15:22:19 [error] 2956#3056: *146 WSARecv() failed (10054: An existing connection was forcibly closed by the remote Host) while reading response header from upstream, client: 158.69.21.193, server: localhost, request: "GET /assets/hk/ajax/recent_logins.php?_=1443392503883 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", Host: "158.69.21.193", referrer: "http://158.69.21.193/hk/index.php?url=index"
2015/09/27 15:22:19 [error] 2956#3056: *145 WSARecv() failed (10054: An existing connection was forcibly closed by the remote Host) while reading response header from upstream, client: 158.69.21.193, server: localhost, request: "GET /assets/hk/ajax/active_content.php?_=1443392503884 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", Host: "158.69.21.193", referrer: "http://158.69.21.193/hk/index.php?url=index"
2015/09/27 15:22:19 [error] 2956#3056: *199 WSARecv() failed (10054: An existing connection was forcibly closed by the remote Host) while reading response header from upstream, client: 158.69.21.193, server: localhost, request: "GET /assets/hk/ajax/active_content.php?_=1443392503882 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", Host: "158.69.21.193", referrer: "http://158.69.21.193/hk/index.php?url=index"
2015/09/27 15:22:19 [error] 2956#3056: *193 WSARecv() failed (10054: An existing connection was forcibly closed by the remote Host) while reading response header from upstream, client: 158.69.21.193, server: localhost, request: "GET /assets/hk/ajax/recent_logins.php?_=1443392503885 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", Host: "158.69.21.193", referrer: "http://158.69.21.193/hk/index.php?url=index"

私はnginx設定ファイルもチェックしましたが、nginxを初めて使用するので、何が問題で何が正しいのか本当に理解できませんので、以下に貼り付けました。

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  15;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/Host.access.log  main;



        location / {
            rewrite ^/(|/)$ /index.php?page=$1;
            rewrite ^/([a-zA-Z0-9_-]+)(|/)$ /index.php?page=$1;
            rewrite ^/(.*).htm$ /$1.php;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /404.php
        #
        error_page   500 502 503 504  /404.php;
        location = /404.php {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ .php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_read_timeout 60000s;
    fastcgi_param  SCRIPT_FILENAME  C:/nginx/html/$fastcgi_script_name;
    include        fastcgi_params;
    }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual Host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

私はこのエラーについて多くのWebサイトを訪問しましたが、それでも最終的に私を助けてくれたWebサイトはまだありません。また、nginxダウンロードパッケージの元のファイルからこのファイルを編集しました。

私のajaxコードはxamppとiisで完全に機能しますが、nginxでは機能しません...

4
Josh Deriosk

私は同じ質問に答えました、解決策はこれらの設定をプロキシに適用することです:

keepalive_requests 500;
proxy_http_version 1.1;
context:  http, server, location 

キープアライブ接続での使用にはバージョン1.1をお勧めします

1
sunweiguang