在nginx中使用$ limit_rate时出现错误404

我有这个configuration在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; } } 

当有人从“/ download /”目录请求某个东西时,我的目标是限制带宽率。 有了这个configuration,当我打开浏览器,我数字的东西像“example.com/download/filename.example”我收到404错误。 如果我从configuration文件中删除“位置/下载/”块,一切正常。

任何人都可以帮我解决它?

我使用nginx / 0.7.67和PHP 5.3.18-1〜dotdeb.0和Suhosin-Patch(cli)

您需要为/ download / location-block设置root指令。

这可以通过在位置块中明确地设置一个根指令来实现,或者在位置块之外但是在服务器块之内放置一个全局的根指令。

select1 – 位置块内的显式根指令

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

备选scheme2 – 服务器块的全局根指令

 server { root /var/www/example.com/public_html; ... location / { index index.html index.htm index.php; } ... location /download/ { set $limit_rate 150k; } }