nginx php跳转url参数,NGINX 中把url中的内容当初参数处理

本文讨论了在Nginx服务器中,如何配置以正确处理URL参数传递给PHP的问题。出现错误是因为rewrite规则导致URL被误识别为文件路径。解决方案是开启PHP的cgi.fix_pathinfo配置选项。通过理解Nginx的location指令和fastcgi_pass参数,可以确保POST参数正确路由。
摘要由CSDN通过智能技术生成

作用:把url为:127.0.0.1/index.php/a/b/c 这样处理

把 post参数: /a/b/c到127.0.0.1/index.php

nginx 配置如下:

server {

listen  80;

server_name     127.0.0.1;

root /home/shaddock/Applications/htdocs;

index index.html index.htm index.php index.js;

access_log logs/access.log;

error_log logs/error.log;

error_page 404  /404.html;

location /404.html {

root /home/shaddock/Applications/htdocs;

}

location /dmp5.0{

index index.html index.htm index.php;

if (-e $request_filename) {

break;

}

if (!-e $request_filename) {

rewrite ^/dmp5.0/(.*)$ /dmp5.0/index.php/$1 last;

break;

}

}

location ~ .+\.php($|/) {

root/home/shaddock/Applications/htdocs;

fastcgi_index index.php;

fastcgi_split_path_info ^(.+\.php)(.*)$;

fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param   PATH_INFO               $fastcgi_path_info;

fastcgi_param   PATH_TRANSLATED $document_root$fastcgi_path_info;

fastcgi_pass   127.0.0.1:9000;

include        fastcgi_params;

}

}

错误:

2017/01/09 10:48:58 [error] 5103#0: *57 open() "/home/shaddock/Applications/htdocs/dmp5.0/index.php/index/index/ajaxLogin" failed (20: Not a directory), client: 127.0.0.1, server: 127.0.0.1, request: "POST /dmp5.0/index/index/ajaxLogin HTTP/1.1", host: "127.0.0.1", referrer: "http://127.0.0.1/dmp5.0/"

上面的错误是因为rewrite的时候直接把url http://127.0.0.1/dmp5.0/index.php/index/index/ajaxLogin当成页面处理了。本意应该是

http://127.0.0.1/dmp5.0/index.php/index/index/ajaxLogin这个url把这些单词参数,传给http://127.0.0.1/dmp5.0/index.php

解决:

php中php.ini中下面参数打开

cgi.fix_pathinfo=1

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值