2

I have this configuration running on nginx

root@homer:/home/admin# cat /etc/nginx/sites-enabled/example.com 
server 
{
listen   80;
server_name www.example.com example.com;
access_log /var/www/example.com/logs/access.log;
error_log /var/www/example.com/logs/error.log;

## Only allow these request methods (do not accept DELETE, SEARCH and others.. ##
if ($request_method !~ ^(GET|HEAD|POST)$ ) {return 444; }

location / 
{
    root   /var/www/example.com/public_html;
    index  index.html index.htm index.php;
}


location ~ \.php$ 
{
    include /etc/nginx/fastcgi_params;

    if ($uri !~ "^/upload/") {fastcgi_pass 127.0.0.1:9000; }

    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /var/www/example.com/public_html$fastcgi_script_name;
}

# Prevent (deny) Access to Hidden Files
location ~ /\.
{
    access_log off;
    log_not_found off; 
    deny all; 
}

# Limit bandwidth rate on a specific folder 
location /download/ 
{ 
    set $limit_rate  150k; 
}   
}

My goal is limit the bandwith rate when someone request something from "/download/" directory. With this configuration when I open the browser and I digit something like "example.com/download/filename.example" I recieve 404 error. If I remove the "location /download/" block from the config file, all works good.

Can anyone help me to fix it?

I use nginx/0.7.67 with PHP 5.3.18-1~dotdeb.0 with Suhosin-Patch (cli)

1 Answer 1

1

You need to set the root directive for the /download/ location-block.

This can be achieved by either explicitly setting a root directive inside the location-block, or put a global root directive outside the location-blocks, but inside the server-block.

Alternative 1 - Explicit root directive inside location-block

location /download/ {
  root /var/www/example.com/public_html;
  set $limit_rate 150k;
}

Alternative 2 - Global root directive for the server-block

server {
  root /var/www/example.com/public_html;

...

  location /  {
    index index.html index.htm index.php;
  }

...

  location /download/ {
    set $limit_rate 150k;
  }
}
2
  • In both alternative configurations, I now receive 403 error Oct 25, 2012 at 13:47
  • Check file permissions.
    – pkhamre
    Oct 25, 2012 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.