nginx的location定义正则后SCRIPT_NAME, PATH_INFO多了index.php
来源:互联网 发布:手写识别数字 算法 编辑:程序博客网 时间:2024/06/06 04:18
在使用nginx进行 反向代理配置时通过正则表达式配置location后发现
通过$_SERVER['SCRIPT_NAME']; 与$_SERVER['PATH_INFO'] 发现直接获取了整个uri地址
访问uri: 127.0.0.1/index.php/site/login
正常情况应该为index.php
先获取为index.php/site/login
以下是解决方法
server {listen 80;server_name test.com;access_log/home/swin/oaih/dev/logs/access.log;error_log /home/swin/oaih/dev/logs/error.log;root /home/swin/oaih/dev/public;index index.php index.html index.htm;location / {if (!-e $request_filename) {rewrite ^/(.*)$ /index.php/$1 last;}}location ~ .php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include /etc/nginx/fastcgi_params;}location ~ .php($|/) {set $script $uri;set $path_info "";if ($uri ~ "^(.+.php)(/.+)") {set $script $1;set $path_info $2;}fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$script;fastcgi_param SCRIPT_NAME $script;fastcgi_param PATH_INFO $path_info;fastcgi_param QUERY_STRING $query_string;fastcgi_param REQUEST_METHOD $request_method;fastcgi_param CONTENT_TYPE $content_type;fastcgi_param CONTENT_LENGTH $content_length;fastcgi_param REQUEST_URI $request_uri;fastcgi_param DOCUMENT_URI $document_uri;fastcgi_param DOCUMENT_ROOT $document_root;fastcgi_param SERVER_PROTOCOL $server_protocol;fastcgi_param GATEWAY_INTERFACE CGI/1.1;fastcgi_param SERVER_SOFTWARE nginx;fastcgi_param REMOTE_ADDR $remote_addr;fastcgi_param REMOTE_PORT $remote_port;fastcgi_param SERVER_ADDR $server_addr;fastcgi_param SERVER_PORT $server_port;fastcgi_param SERVER_NAME $server_name;fastcgi_param REDIRECT_STATUS 200;}}
第一个位置指令设立的基本选项,而第二个location指令匹配一个请求到自身的index.php,并把它传递到FastCGI来处理。下一次请求index.php是没有进行正确的配置。
在处理我们的问题的整个配置文件的关键部分是这样的:
location ~ .php($|/) {set $script $uri;set $path_info "";if ($uri ~ "^(.+.php)(/.+)") {set $script $1;set $path_info $2;}fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$script;fastcgi_param SCRIPT_NAME $script;fastcgi_param PATH_INFO $path_info;}
location指定匹配所有的php请求将不指定为先前的全部uri, 它还清空$path-info变量, if语句匹配任何类似下面的请求:http://mysite/index.php/foo和放入的index.php的$script变量和/ foo $path_info变量。
- nginx的location定义正则后SCRIPT_NAME, PATH_INFO多了index.php
- Nginx/PHP/path_info问题,去掉index.php
- Nginx配置隐藏index.php和PATH_INFO支持
- Nginx配置隐藏index.php和PATH_INFO支持
- Nginx(PHP/fastcgi)的PATH_INFO问题
- Nginx(PHP/fastcgi)的PATH_INFO配置
- Nginx(PHP/fastcgi)的PATH_INFO配置
- nginx的php fastcgi模式PATH_INFO解决办法Magento正常
- yii2 如何使用 PATH_INFO 模式 并去掉 index.php
- nginx location的正则匹配规则
- nginx支持yaf的path_info配置
- nginx location正则写法
- 让nginx支持PATH_INFO
- nginx配置path_info
- 配置nginx支持PATH_INFO
- 配置nginx支持 PATH_INFO
- nginx支持path_info
- nginx去掉index.php
- linux下 mysql密码忘记的解决方法
- ssh连接两个数据库
- oracle打补丁步骤简介
- 程序员面试宝典,如何删除代码的注释
- 实习流水帐
- nginx的location定义正则后SCRIPT_NAME, PATH_INFO多了index.php
- 第十五周任务(二)
- 备份的sql文件乱码无法导入
- 网页电话/手机号码识别
- DirectX11解析
- 第一篇LISP小程序
- UNIX网络I/O模型
- ultraedit 正则表达式 -删除包含某个字符串的所有行
- Linux 关于shell 的一些学习