How to do it...

Limiting bandwidth must be done within a location directive. It's important to ensure that, if you have multiple location block directives which you want to limit, you need to adjust each of these. Here's our basic code:

server { 
    listen 80; 
    server_name limitbw.nginxcookbook.com; 
    access_log  /var/log/nginx/limitbw.log  combined; 
    location / { 
        limit_rate 5m; 
        root   /var/www/html; 
        index  index.html index.htm; 
    } 
}