首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nginx暂时挂起一些帖子请求。

nginx暂时挂起一些帖子请求。
EN

Server Fault用户
提问于 2020-01-18 11:19:18
回答 1查看 2.2K关注 0票数 0

我在Ubuntu18.08上运行了以下堆栈,并将其定义为:

  1. mariadb:10.3.20实例
  2. 基于wordpress:5.3.0-php7.2的自定义wordpress实例及其上安装的ioncube
  3. 基于nginx:1.13的自定义nginx实例及其上安装的nginx-amplify-agent

nginx的配置:

代码语言:javascript
复制
user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  10000;
}

http {
    include       /etc/nginx/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"';

    log_format  main_ext  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for" '
                          '"$host" sn="$server_name" '
                          'rt=$request_time '
                          'ua="$upstream_addr" us="$upstream_status" '
                          'ut="$upstream_response_time" ul="$upstream_response_length" '
                          'cs=$upstream_cache_status' ;

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

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

网站的定义如下:

代码语言:javascript
复制
server {
        listen 80;
        listen [::]:80;

        server_name some.org www.some.org;

        location / {
                rewrite ^ https://$host$request_uri? permanent;
        }
}

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name some.org www.some.org;

        index index.php index.html index.htm;

        root /var/www/html;

        server_tokens off;

        ssl_certificate /etc/letsencrypt/live/some.org/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/some.org/privkey.pem;

        add_header X-Frame-Options "SAMEORIGIN" always;
        add_header X-XSS-Protection "1; mode=block" always;
        add_header X-Content-Type-Options "nosniff" always;
        add_header Referrer-Policy "no-referrer-when-downgrade" always;
        add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always;
        # add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
        # enable strict transport security only if you understand the implications

        location / {
                proxy_connect_timeout 600;
                proxy_send_timeout    600;
                proxy_read_timeout    600;
                proxy_redirect        off;
                proxy_pass http://wordpress;

                proxy_set_header      X-Real-IP $remote_addr;
                proxy_set_header      X-Forwarded-Proto https;
                proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header      Host $host;
        }

        location = /favicon.ico {
                log_not_found off; access_log off;
        }

        location = /robots.txt {
                log_not_found off; access_log off; allow all;
        }

        location ~* \.(css|js|gif|ico|jpeg|jpg|png)$ {
                expires max;
                log_not_found off;
        }
}

整个堆栈按照预期工作,除非10-15个用户来到网站并尝试执行操作。在这种情况下,一些请求开始挂起(通常是对某个组件的POST请求),3-4分钟后,它被释放,没有任何错误,用户实际上可以看到它的结果。在挂起的网站变得不负责从同一个浏览器(但从其他人,一切都好!)一旦请求发布-网站再次负责。

日志也很奇怪:

  • 一旦挂起/挂起请求到达服务器,它将显示在nginx访问日志中,而不显示在wordpress日志中。
  • 一旦请求最终被释放(即处理),它将在nginx访问日志和wordpress日志中第二次显示,但时间不同

nginx访问日志:

代码语言:javascript
复制
62.96.39.243 - - [17/Jan/2020:10:56:41 +0000] "GET /something

78.43.40.52 - - [17/Jan/2020:10:56:41 +0000] "POST /ajax-bidsform.html?meth=post&yid=d7f9f1a1a0bf HTTP/2.0" 200 208 "https://some.org/xchange_XRP_to_SBERRUB/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36" "-"

78.43.40.52 - - [17/Jan/2020:10:56:41 +0000] "GET /something

wordpress:

代码语言:javascript
复制
134.19.130.91 - - [17/Jan/2020:10:56:40 +0000] "GET /something

78.43.40.52 - - [17/Jan/2020:10:50:07 +0000] "POST /ajax-bidsform.html?meth=post&yid=d7f9f1a1a0bf HTTP/1.0" 200 559 "https://some.org/xchange_XRP_to_SBERRUB/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36"

62.96.39.243 - - [17/Jan/2020:10:56:41 +0000] "GET /something

如您所见,挂起的POST /ajax-bidsform.html...在nginx日志中的时间是10:56,在wordpress中是10:50 -而这正是客户端完成此请求的时间。据我所知,这意味着该请求在nginx级别上停留了将近6分钟,直到它实际上被传递给wordpress。如您所见,我没有nginx的ddos保护指令。

另外,我也注意到:在挂起的请求中,没有任何CPU或RAM的长期峰值,因此很可能与硬件问题无关。我还在想,它在某种程度上与挂起的脚本(即ajax-bidsform.html)有关,但只有当我们从虚拟主机迁移到数字海洋的云实例(以前从未发生过)时,它才开始发生,所以我想这是一个配置问题。日志中请求的时间线也可以证明这一点。

到目前为止,我确实试图:

  1. worker_connections提高到10000
  2. 将nginx实例的(而不是主机的) net.core.somaxconn增加到1024

但问题仍在发生..。任何想法或想法都将不胜感激!

EN

回答 1

Server Fault用户

回答已采纳

发布于 2020-01-18 17:55:12

10:56在nginx日志中,10:50在wordpress中

我将把这理解为wordpress在10:50接收请求,并在10:56将结果返回给nginx。要确定,您可以在nginx中将upstream_response_time添加到log_format中。见利用NGINX测井技术进行应用性能监测

票数 2
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/999456

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档