在Nginx上匹配404错误的所有位置

我正在将一个编译的CGI从IIS移植到Nginx,该应用程序使用自定义错误404来执行Url重写和静态文件caching,在IIS中这个工作

<httpErrors> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" prefixLanguageFilePath="" path="/index.exe" responseMode="ExecuteURL" /> </httpErrors> 

它将request_uri传递给index.exe,然后像这样

example.com/users

在内部处理为

example.com/index.exe?module=users

或类似的东西

example.com/blog/my-first-post.html

被处理为

example.com/index.exe?module=blog&postname=my-first-post

在Nginx的我想这个(在另一台服务器上的后台运行的CGI)

 server { listen 80; server_name example.com; root E:/domains/example.com; index index.html index.htm default.html default.htm; location ~* ^\/.* { proxy_pass http://localhost:5001; } } 

但是,如果我进入example.com/users我得到一个403错误…

请任何帮助将感激:)