Showing posts with label upstream timed out. Show all posts
Showing posts with label upstream timed out. Show all posts

Monday, July 6, 2020

Python reverse proxy nginx : [error] upstream timed out (110: Connection timed out) while reading response header from upstream

Generally python server script execution time does not bother too much and server persons do not struggle with them like apache/php but  sometimes similar conditions may arrive.

Developers do not use any reverse proxy web server like nginx or apache to resolve the port on the domain. They access the site with localhost and port. Here they do not get 'connection time out' 'bad gateway' or similar issues. They see the error on command line and start fixing them.

But reverse proxy web servers do not log 'server side language error', they show the error in the format of internal server error like 501, 502, 503 etc

In above error Python django or any other framework script takes too long to complete but developer do not get similar error on localhost as there is no parameter which halts the script the execution. This is real headache of server person.

In this scenario, script execution time needs to increase in web server.

Solution :
Open virtual host in the nginx and add the parameters under vrtualhost of domain.

Add under location /
 proxy_connect_timeout       3600;
 proxy_send_timeout          3600;
 proxy_read_timeout          3600;
 send_timeout                3600;


The time is in second.
Complete snippet of 'location /'should look like this.
  location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:8000/;
        proxy_set_header X-Forwarded-Proto $scheme;
                proxy_hide_header X-Powered-By;
                server_tokens off;
                autoindex off;
                etag off;
  proxy_connect_timeout       6000;
  proxy_send_timeout          6000;
  proxy_read_timeout          6000;
  send_timeout                6000;
 }

Restart nginx.

Now timeout error should not be there again.