Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the appropriate NGINX configs if you are only sending JSON objects?

I'm an iOS developer and my back end is all written in Django. I use gunicorn as my HTTP server. I have three workers running on a small EC2 instance.

My iOS app does not require any images or static content. At most, I am sending 1-20 JSON objects at a time per request. Each JSON object has at most about 5-10 fields.

I'm quite new to NGINX. I heard it can do proxy buffering. I would like to add proxy buffering for slow clients, but I don't know the appropriate specific settings to use for the following modules:

proxy_buffers
Syntax:     proxy_buffers number size
Default:    8 4k|8k
Context:    http server location
Reference:  proxy_buffers


proxy_busy_buffers_size
Syntax:     proxy_busy_buffers_size size
Default:    8k|16k
Context:    http server location
Reference:  proxy_busy_buffers_size

proxy_buffer_size
Syntax:     proxy_buffer_size size
Default:    4k|8k
Context:    http server location
Reference:  proxy_buffer_size

The only setting which I know how to use (which is pretty sad) is the one below:

proxy_buffering
Syntax:     proxy_buffering on | off
Default:    on
Context:    http server location
Reference:  proxy_buffering

Your expertise in this area would be greatly appreciated by this kind lost soul!

like image 247
deadlock Avatar asked Jun 13 '13 16:06

deadlock


People also ask

What is Nginx reverse proxy?

A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs client requests to the appropriate backend server. A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.

How do you check if Nginx reverse proxy is working?

To check the status of Nginx, run systemctl status nginx . This command generates some useful information. As this screenshot shows, Nginx is in active (running) status, and the process ID of the Nginx instance is 8539.

What is keep alive in Nginx?

In Nginx, keepalive is a directive that is utilized for keeping the connection open for a certain number of requests to the server or until the request timeout period has expired.

What is upstream Nginx?

upstream defines a cluster that you can proxy requests to. It's commonly used for defining either a web server cluster for load balancing, or an app server cluster for routing / load balancing.


1 Answers

proxy_buffers

The number defines how many buffers nginx will create and the size how big each buffer will be. When nginx starts receiving data from the upstream it starts filling up those buffers, either until the buffers are full or the upstream sends EOF or EOT. If any of those two conditions is met, nginx will send the contents of the buffers to the client.

If the client isn’t reading the buffers quickly enough, it will attempt to write the contents of them to disk and send them when the client is able to receive.

Take the average size of your JSON responses. Modern disks and file systems can handle even huge buffer sizes, but you should use something to the power of two and by creating a good balance between the number and size you can speed up the buffering process.

proxy_busy_buffers_size

These are buffers that were already passed downstream but not yet completely send and therefor they can’t be reused. This directive limits the maximum total size of such buffers and thus allows remaining buffers to be used to read upstream responses.

proxy_buffer_size

The main buffer that is always in use. Even if you disable proxy_buffering, nginx will still fill up this buffer and flush it as soon as it’s full or EOF/EOT.

proxy_max_temp_file_size

This directive controls how many data might be written to disk if the buffers are full (still utilizing in-memory buffers, because you need them to communicate with the disk). If all buffers and this file are full, nginx stops reading from upstream and has to wait for downstream to fetch the data before it can continue with the same procedure.

like image 157
Fleshgrinder Avatar answered Nov 15 '22 05:11

Fleshgrinder