Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx 文档配置错误。 #503

Closed
xieye114 opened this issue Jul 10, 2020 · 5 comments
Closed

nginx 文档配置错误。 #503

xieye114 opened this issue Jul 10, 2020 · 5 comments

Comments

@xieye114
Copy link

文档上有错
错误的写法:
if (!-e $request_filename) {
rewrite ^/(.) /index.php/$1 last;
}
正确的写法
if (!-e $request_filename) {
rewrite ^/(.
) /index.php?$1 last;
}

@sansanboy
Copy link

区别是什么没有看出来

@infatu8
Copy link

infatu8 commented Dec 27, 2020

使用 / 需要配置好 nginx 以支持url pathinfo模式
至于nginx rewrite中的 $1 以及 如何配置nginx支持pathinfo 之类的 自行百度谷歌

如:
未支持pathinfo前 url类如 http://127.0.0.1/test.php?a=1&b=2
支持pathinfo后 就用 http://127.0.0.1/test.php/a/1/b/2

@letwang
Copy link

letwang commented Aug 7, 2021

PHP8 Yaf3.3.3 按照官网配置 导致Nginx死循环:

2021/08/08 03:29:47 [error] 6188#6188: *2 rewrite or internal redirection cycle while processing "/index.phpindex.phpindex.phpindex.phpindex.phpindex.phpindex.phpindex.phpindex.phpindex.phpindex.phpindex.phprbac_group", client: 172.17.0.1, server: www.admin.com, request: "GET /rbac_group HTTP/2.0", host: "www.admin.com:81", referrer: "https://www.admin.com:81/"

解决:
Example #3 Rewrite rule

#for nginx

server {
  listen ****;
  server_name  domain.com;
  root   document_root;
  index  index.php index.html index.htm;

  if (!-e $request_filename) {
    rewrite ^/(.*)  /index.php?$1 last;
  }
}

唯一的变化,是 多出1个 ?问号

@laruence
Copy link
Owner

?意思是query_string, /意思是PATH_INFO

@jingjingxyk
Copy link

jingjingxyk commented Jul 6, 2024

关键地方是 调用 fastcgi 是缺少 PATH_INFO

这两行

            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        if (!-e $request_filename) {
            rewrite ^/(.*)  /index.php?$1 last;
        }

        # 关键点: 
        location ~ ^/index\.php(/|$) { 
            # fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            # fastcgi_pass  /var/run/php-fpm.sock ;

            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;

            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
            fastcgi_hide_header X-Powered-By;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants