通过一个请求在 nginx 中插入多个请求

insert multi request in nginx by one request

我是 android 开发人员,我的应用程序请求我的服务器下载文件

Log.d("SBP", f_url[0]);
URL url = new URL(f_url[0]);
URLConnection conection = url.openConnection();

在调试中显示一个请求,但在服务器中当我打开 access.log 我看到 2 个或更多相同的请求! :|

但是为什么???

这是我的nginx.config

user  nginx;
worker_processes  1;
worker_rlimit_nofile 20000;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
 worker_connections  1024;
 }


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"';

#access_log  /var/log/nginx/access.log  main;

 sendfile        on;
 #tcp_nopush     on;

 keepalive_timeout  65;

 #gzip  on;

 include /etc/nginx/conf.d/*.conf;
 include /etc/nginx/sites-enabled/*;
 }

这是我的网站配置:

    server {
    server_name MYSITE;
    access_log /srv/www/MYSITE/logs/access.log;
    error_log /srv/www/MYSITE/logs/error.log;
    root /srv/www/MYSITE/public;

    client_max_body_size 20m;
    client_body_buffer_size 128k;

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

    location / {
        index index.html index.htm index.php;
    }

location ~ /\. {
    access_log off;
    log_not_found off;
    deny all;
}

    location ~* \.php$ {
       # include /etc/nginx/fastcgi_params;
        server_tokens off;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }
}

您的问题是由 Volley RetryPolicy 引起的。要修复它(如 there and there 所示),您需要禁用重试:

myRequest.setRetryPolicy(new DefaultRetryPolicy(
    DefaultRetryPolicy.DEFAULT_TIMEOUT_MS,
    0,
    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

或增加超时(本例中为 10 秒而不是默认的 2.5):

myRequest.setRetryPolicy(new DefaultRetryPolicy(
    DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 4,
    DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

有关 RetryPolicy 工作原理的更多信息,请参见 there, it's defaults can be found here