NGINX rewrite重定向403错误排除

一次NGINX rewrite重定向403错误排除
以下2个网址,第一个(没有.php字样)的正常,第二个会显示403错误,但返回内容
http://api.cn/type/item_get/?
http://api.cn/type/api_call.php?api_name=item_get

更多方法请移步:
http://console.open.onebound.cn/console/?i=Turbo

与第一个一致,由于部分客户端会根据HTTP状态判断网络请求是否成功,于是必须修复。
经过排查,凡是URL中出现.php即会报错(?符号后不影响)
尝试删除nginx/conf/fcgi.conf中的403输出,但又会输出404
最后检查到问题出在try_files语句上,可能是它将type/api_call.php传给了/index.php?type/api_call.php
导致fcgi.conf解析PHP脚本路径时判断错误
于是在location / 上面添加一个REWRETE语句解决
rewrite ^/(.*)api_call.php$ /index.php?$1 last;相关配置文件

nginx/conf/vhost/api.conf
server {
listen 80;
root /www/web/api/public_html;
server_name api.cn;
index index.html index.php index.htm;
error_page 400 /errpage/400.html;
error_page 403 /errpage/403.html;
error_page 404 /errpage/404.html;
error_page 503 /errpage/503.html;

#最后添加的代码解决403问题
#rewrite ^/(.*)api_call.php$ /index.php?$1 last;

location / {
try_files $uri u r i / / ? uri/ /?uri//?args;
}
location ~ .php(.*)$ {
fastcgi_pass unix:/tmp/php-70-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME D O C U M E N T R O O T DOCUMENT_ROOTDOCUMENT 
R
​    
 OOTfastcgi_script_name;
fastcgi_param PATH_INFO $2;
include fcgi.conf;
}
location ~ /.ht {
deny all;
}
}

nginx/conf/fcgi.conf

if ($request_filename ~* (.*).php) {
set $php_url $1;
}
if (!-e $php_url.php) {
return 403;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

佩奇搞IT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值