2

Please note, I have referred to THIS QUESTION however this did not fix the issue...

As you can see from the nginx error log, I am sending a post request to /order-history. This will then run a SQL query that takes about a minute, however, the connection is prematurely closing. This issue does not occur when the application is deployed with the flask test server obviously, as the logs point out :)

/var/log/nginx/error.log:

2018/05/30 15:34:04 [error] 12294#12294: *9 upstream prematurely closed connection while reading response header from upstream, client: 192.168.96.116, server: alpha2, request: "POST /order-history HTTP/1.1", upstream: "http://unix:/home/hleggio/myproject/myproject.sock:/order-history", host: "alpha2:5000", referrer: "http://alpha2:5000/query-selection"

/etc/nginx//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 65;
    types_hash_max_size 2048;
    fastcgi_read_timeout 99999;
    proxy_read_timeout 99999;
    # server_tokens off;



    client_max_body_size 20M;

    # 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/*;
}

/etc/nginx/sites-available/myproject:

server {
    listen 5000;
    server_name alpha2;

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/hleggio/myproject/myproject.sock;
        proxy_read_timeout 9999;
        proxy_connect_timeout 9999;
        proxy_request_buffering off;
        proxy_buffering off;
    }
}
Harrison
  • 5,095
  • 7
  • 40
  • 60

1 Answers1

3

I was able to solve this issue. This wasn't related to my NGINX configuration.

The problem resided in my Gunicorn configuration file.

In my Gunicorn config file (/etc/systemd/system/myproject.service), I added the following to my ExecStart line:

--timeout 600

The file now looks like this:

[Unit]
Description=Gunicorn instance to serve myproject
After=network.target

[Service]
User=harrison
Group=www-data
WorkingDirectory=/home/harrison/myproject
Environment="PATH=/home/harrison/myproject/myprojectenv/bin"
ExecStart=/home/harrison/myproject/myprojectenv/bin/gunicorn --workers 3 --timeout 600 --bind unix:myproject.sock -m 007 wsgi:application

[Install]
WantedBy=multi-user.target
Harrison
  • 5,095
  • 7
  • 40
  • 60