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

时间:2015-06-16 08:00:16

标签: nginx rewrite

我有这个conf,

    rewrite "^download/([0-9a-f]{32})/(.+)$" /download.php?h=$1&f=$2 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;
    }

但是当我尝试打开网址时,http://example.com/download/d3ef6bbeaff9b429680bca646e8ee1cf/video.mp4 它返回404 Not Found 我尝试将rule放入任何location,但没有帮助 直接链接到文件http://example.com/download.php正在运行,需要为工作rewrite做些什么? 我看到很多关于它的线索,但解决方案没有帮助我,但是错了吗?

在服务器nginx + php-fpm

1 个答案:

答案 0 :(得分:1)

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

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