$ _POST为空. Nginx OSx [英] $_POST is empty. Nginx OSx

查看:97
本文介绍了$ _POST为空. Nginx OSx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问$_POST,它为空.

I'm trying to access $_POST and it's empty.

如果我尝试在根目录(即localhost)上访问它,它会起作用. 如果我尝试访问其他文件夹(即localhost/foo),则无法使用.

If I try to access it on the root (ie. localhost), it WORKS. If I try to access in a different folder (ie. localhost/foo), it DOESN'T WORK.

这是我的配置文件:

 server {
        listen   80;    

        root /var/www;
        index index.php index.html index.htm;

        server_name localhost;

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;
        }

        # pass the PHP scripts to FastCGI server listening on the php-fpm socket
        location ~ \.php {
                try_files $uri =404;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

}

这是原始的RAW请求示例:

Here is a sample RAW request:

POST /dev/post-test HTTP/1.1
Host: localhost
Cache-Control: no-cache

----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="action"

store
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="id"

4315251
----WebKitFormBoundaryE19zNvXGzXaLvS5C

出什么问题了?

谢谢.

推荐答案

此differnet行为的关键是路径中的尾部斜杠.

The key on this differnet behavier is the trailing slash in the route.

对于nginx,以下是两个不同的请求:

For nginx the following are two different requests:

http://localhost/foo
http://localhost/foo/

第一个结果是内部301重定向(到index.php到该文件夹​​),其中$ _POST值丢失了.

The first one result in an internal 301 redirect (to index.php into that folder), where the $_POST values are lost.

有关此行为的更多信息以及防止该行为的解决方案,请阅读以下答案: 如果没有尾部斜杠,Nginx会导致301重定向

More about this behavior and solution to prevent it, read the answers below: Nginx causes 301 redirect if there's no trailing slash

这篇关于$ _POST为空. Nginx OSx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆