AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 447671
Accepted
Tar
Tar
Asked: 2012-11-12 16:00:03 +0800 CST2012-11-12 16:00:03 +0800 CST 2012-11-12 16:00:03 +0800 CST

网站连接在第一次加载时重置

  • 772

我将 nginx 与 php-cgi 一起使用。最近出现了一个问题,如果您有一段时间没有查看我的网站,比如 3-4 分钟,然后再次打开它,您发送的第一个请求将在浏览器中返回 connection reset by peer。如果刷新,所有后续请求的操作都是正常的。这种情况每次都会发生,这不仅仅是一个孤立的事件,它发生在每个使用我网站的人身上。我试图重新启动 nginx 和 php-cgi 但无济于事。有谁知道是什么问题?我可以提供任何必要的信息。

值得注意的是,除了有关客户端提前关闭连接的消息外,错误日志中没有任何内容。

nginx 配置文件

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;
}

默认.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;
}
}
nginx
  • 2 2 个回答
  • 3830 Views

2 个回答

  • Voted
  1. Apurva Sukant
    2012-11-13T00:22:26+08:002012-11-13T00:22:26+08:00

    你首先要确定,这个故障发生在哪一层,即服务器层(Linux机器配置),PHP(php.ini,php-cgi)层,还是你的应用层。HTTP 错误可能是由任何这些层的配置不正确引起的,因此您需要首先隔离并确定发生服务器故障(双关语)的确切位置。

    我的建议是跟踪 HTTP 请求:

    1. 从它到达您的服务器的那一刻起,通过 Linux 配置。
    2. 然后通过Nginx配置(nginx.conf,default.conf)。
    3. 然后通过PHP和PHP-CGI。
    4. 最后在它到达您的应用程序后对其进行分析,并检查您的应用程序如何使用它来发送 http 响应。

    通过这种方式,您将能够准确地确定问题出在哪里,然后服务器故障的好人才能帮助您正确解决问题!

    同时发布你的 nginx.conf、default.conf、php-fpm.conf 一些关于你的应用程序的细节也很好。

    • 1
  2. Best Answer
    Tar
    2012-11-19T14:04:59+08:002012-11-19T14:04:59+08:00

    发布了一个新的 nginx 更新 (1.2.5) 并更新到较新的版本解决了这个问题。

    • 0

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve