Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.


I would like to test all Nginx proxy timeout parameters in very simple scenario. My first approach was to create really simple HTTP server and put some timeouts:

  1. Between listen and accept to test proxy_connect_timeout
  2. Between accept and read to test proxy_send_timeout
  3. Between read and send to test proxy_read_timeout


1) Server code (python):

import socket
import os
import time
import threading

def http_resp(conn):
    conn.send("HTTP/1.1 200 OK\r\n")
    conn.send("Content-Length: 0\r\n")
    conn.send("Content-Type: text/xml\r\n\r\n\r\n")

def do(conn, addr):
    print 'Connected by', addr
    print 'Sleeping before reading data...'
    time.sleep(0) # Set to test proxy_send_timeout
    data = conn.recv(1024)
    print 'Sleeping before sending data...'
    time.sleep(0) # Set to test proxy_read_timeout
    print 'End of data stream, closing connection'

def main():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.bind(('', int(os.environ['PORT'])))
    print 'Sleeping before accept...'
    time.sleep(130) # Set to test proxy_connect_timeout
    while 1:
        conn, addr = s.accept()
        t = threading.Thread(target=do, args=(conn, addr))

if __name__ == "__main__":

2) Nginx configuration:

I have extended Nginx default configuration by setting explicitly proxy_connect_timeout and adding proxy_pass pointing to my local HTTP server:

    location / {
        proxy_pass http://localhost:8888;
        proxy_connect_timeout 200;

3) Observation:

proxy_connect_timeout - Even though setting it to 200s and sleeping only 130s between listen and accept Nginx returns 504 after ~60s which might be because of the default proxy_read_timeout value. I do not understand how proxy_read_timeout could affect connection at so early stage (before accept). I would expect 200 here. Please explain!

proxy_send_timeout - I am not sure if my approach to test proxy_send_timeout is correct - i think i still do not understand this parameter correctly. After all, delay between accept and read does not force proxy_send_timeout.

proxy_read_timeout - it seems to be pretty straightforward. Setting delay between read and write does the job.

So I guess my assumptions are wrong and probably I do not understand proxy_connect and proxy_send timeouts properly. Can some explain them to me using above test if possible (or modifying if required).

share|improve this question
You should test your server with telnet. I'm not convinced that a connection is established till after 130 seconds. But it's also possible the timeouts aren't serialized, but run in parallel, so whichever is the shortest wins. –  Melvyn Jun 26 '13 at 6:39
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.