nginx + php-fpm 重写规则不起作用

nginx + php-fpm Rewrite rule not working

我有这个配置,

    rewrite "^download/([0-9a-f]{32})/(.+)$" /download.php?h=&f= last;
    location / {
            index index.html;
    }
    location ~ \.php$ {
            fastcgi_pass unix:/var/run/php-fpm.apache.sock;
            fastcgi_index index.html;
            fastcgi_param SCRIPT_FILENAME $root_path$request_filename;
            include fastcgi_params;
    }

但是当我尝试打开 url、http://example.com/download/d3ef6bbeaff9b429680bca646e8ee1cf/video.mp4 这是 return 404 Not Found 我尝试将 rule 放入任何 location,但没有帮助。
直接 link 到文件 http://example.com/download.php 正在工作,工作 rewrite 需要做什么?
我看到了很多关于它的帖子,但解决方案对我没有帮助,怎么了?

在服务器 nginx + php-fpm

Nginx 的重写始终匹配以斜杠开头的完整 URI。所以你需要修复你的重写:

rewrite "^/download/([0-9a-f]{32})/(.+)$" /download.php?h=&f= last;