Score:0

Limiting upload bandwidth in Nginx

us flag

I'm trying to limit the upload rate (bytes/second) for a downstream client connected to an Nginx proxy.

I'm managed to do this through the configuration below, but I'm not sure if this is the best solution.

http {
  server {
    listen 8086;
    proxy_http_version 1.1;
    location = / {
      proxy_pass http://some-mock-upstream:8086/;
    }
  }
}

stream {
   server {
     listen 8085;
     proxy_upload_rate 50k;
     proxy_pass 127.0.0.1:8086;
   }
}

Initially the request would arrive on port 8085 (i.e. the TCP layer 4 listener). From there it would be forwarded to port 8086 (i.e. the HTTP layer 7 listener). Even though it isn't shown above, I need the request to go through the server block under the http context because I need to update some headers.

Is there another way to limit the upload bandwidth, or is what I have above okay? Does it make sense to have an extra hop added?

djdomi avatar
za flag
why dont you use that in the first location?
lbj-ub avatar
us flag
It seems like the `proxy_upload_rate` directive can't be added under the `http` context; I guess it operates on the transport layer of the OSI model. Not sure if that answers your question.
djdomi avatar
za flag
have you tsken a look at http://nginx.org/en/docs/stream/ngx_stream_proxy_module.html#proxy_upload_rate it states that it csn be used within the server part
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.