我一直在尝试使用Restler php api。
我的the服务器的根目录下有一个api.php文件:
<?php
require_once('lib/restler.php');
class Say {
function hello($to='world') {
return "Hello $to!";
}
}
$r = new Restler();
$r->addAPIClass('Say');
$r->handle();
?>我试着用最简单的例子GET api.php/ an /hello,但nginx总是给我一个错误404。在日志中我看到“不是一个目录”。
我猜是我的nginx conf出了问题,但是找不到任何关于它的具体信息。有什么想法吗?
发布于 2012-04-14 20:45:05
要解决我的问题:
我将代码放入/api/index.php
然后修改我的nginx配置,添加:
location /api {
if (!-f $request_filename) {
rewrite ^(.*)$ /api/index.php last;
}
if (!-d $request_filename) {
rewrite ^(.*)$ /api/index.php last;
}
}因此,现在如果我调用GET /api/say/hello,它将重定向到/api/index.php/say/hello,并且重写规则允许restler发挥它的魔力。
我希望这会对nginx上restler的未来用户有所帮助。
发布于 2012-04-11 16:43:44
查看rewrite module,看看如何让nginx接受api.php/say/hello URL。
发布于 2013-04-22 22:28:10
经过前面的考虑,即使解决方案有效,根据nginx文档- (IfIsEvil http://wiki.nginx.org/IfIsEvil) -您应该能够在没有if的情况下做到这一点,如下所示:
location /api {
try_files $uri /api/index.php;
#if (!-f $request_filename) {
# rewrite ^(.*)$ /api/index.php last;
#}
#if (!-d $request_filename) {
# rewrite ^(.*)$ /api/index.php last;
#}
}希望这对其他人有帮助。
https://stackoverflow.com/questions/10102616
复制相似问题