R 管道工 API : Prevent "504 Gateway Time-out"

标签 r nginx timeout http-status-code-504 plumber

我已经使用 plumber 编写并部署了一个 R API到 instructions 中的 Digital Ocean 液滴.

我在 .json 数据中发布并期待返回 .json 数据。为此,我使用命令行中的 curl 命令,例如:

curl --data @data/data.json http://[API ADDRESS] > results/output.json

当我发布一个小数据集时,这工作正常,但随着数据集变大,我开始收到如下 HTTP 错误:

<html>
<head><title>504 Gateway Time-out</title></head>
<body bgcolor="white">
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx/1.10.0 (Ubuntu)</center>
</body>
</html>

我尝试编辑 /etc/nginx/nginx.conf 以允许更长的超时和更大的文件,但仍然没有成功。 nginx.conf文件如下:

    user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 3000;
    types_hash_max_size 2048;
    # server_tokens off;

        ##
        # Allow for longer jobs
        ##

        client_header_timeout 3000;
        client_body_timeout 3000;
        fastcgi_read_timeout 3000;
        client_max_body_size 100M;
        fastcgi_buffers 8 128k;
        fastcgi_buffer_size 128k;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

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

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

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

}

然后我使用 sudo service nginx restart 重新启动 nginx 服务器,但仍然出现超时错误。

/var/log/nginx/error.log行内容如下:

*4 upstream timed out (110: Connection timed out) while reading response header from upstream, client: [MY IP], server: _, request: "POST [API]", upstream: "http://127.0.0.1:8000/[API]", host: "[HOST ADDRESS]"

如果您能就水管工的工作原理提供任何帮助或提示,那将非常有用。非常感谢!

最佳答案

我现在已通过将以下行添加到 /etc/nginx/sites-available/[my site]/mysite.conf

来解决此问题
location {
    # time out settings
    proxy_connect_timeout 3000s;
    proxy_send_timeout   3000;
    proxy_read_timeout   3000;
}

我还在 nginx.conf 中注释掉了 keepalive_timout 标志,并在 this article 中指定了 http 版本。但我不确定到底是什么造成了差异。如果我发现我会更新答案。

关于R 管道工 API : Prevent "504 Gateway Time-out",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44628829/

相关文章:

r - 如何操作tmap图例?

url - 使用相同的 URL 提供不同的页面

.htaccess - 亚马逊弹性 beantalk : Use nginx/apache to forward subdomains to subfolders

c++ - glMapBufferRange 卡住 OpenGL 驱动程序

windows-7 - 如何在 Win 7 中延长应用程序超时时间?

r - 带有 gridSVG 和 ggplot2 v.0.9.0 的交互式点标签

r - 根据 R 中缺失数据的时间序列计算周平均值

r - 有没有办法删除数据集中符号相反的对?

nginx - 如何在Kubernetes中为多个服务设置粘性 session ?

tcp - HAProxy 关闭长期存在的 TCP 连接,忽略 TCP keepalive