首页 > 后端开发 > php教程 > nginx配置中rewrite的问题

nginx配置中rewrite的问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-06-06 20:28:48
原创
1433 人浏览过

我想实现用户请求 x.com/api/dosomething 转发到网站根目录下的/api.php处理.
不存在的文件交给 /index.php处理,nginx配置如下

<code> if (!-e $request_filename) {
         rewrite (.*) /index.php$1 last;
     }

location ^~ /api/{
    rewrite (.*) /api.php$1 last;
}

location ~ (index|api|admin).php {
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
         include fastcgi_params;
         fastcgi_param PATH_INFO $fastcgi_path_info;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     }</code>
登录后复制
登录后复制

但是我发现访问x.com/api/dosomething的时候匹配了 ! -e $request_filename,调准顺序也没有用,请问应该如何配置

回复内容:

我想实现用户请求 x.com/api/dosomething 转发到网站根目录下的/api.php处理.
不存在的文件交给 /index.php处理,nginx配置如下

<code> if (!-e $request_filename) {
         rewrite (.*) /index.php$1 last;
     }

location ^~ /api/{
    rewrite (.*) /api.php$1 last;
}

location ~ (index|api|admin).php {
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
         include fastcgi_params;
         fastcgi_param PATH_INFO $fastcgi_path_info;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     }</code>
登录后复制
登录后复制

但是我发现访问x.com/api/dosomething的时候匹配了 ! -e $request_filename,调准顺序也没有用,请问应该如何配置

咋一看配置没错啊,我本地试试再说。。。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
重启nginx出错
来自于 1970-01-01 08:00:00
0
0
0
server - Nginx配置webapp问题
来自于 1970-01-01 08:00:00
0
0
0
Nginx的default.conf问题
来自于 1970-01-01 08:00:00
0
0
0
centos7 - NGINX出现异常
来自于 1970-01-01 08:00:00
0
0
0
uwsgi - 如何用nginx关联django应用
来自于 1970-01-01 08:00:00
0
0
0
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板