Nginx的外部POST返回302

我有一个使用Nginx 1.1.4 + PHP-FPM + APC的服务器设置。 在此服务器上运行Magento 1.5.1.0安装。 我遇到的麻烦是来自支付提供者的callback是一个POST,Nginx返回一个302,这使得callback失败。

这是Nginx网站的configuration文件:

 server { listen 80; server_name <domain>; root <path to root>; if ($host ~* ^([a-z0-9\-]+\.(com|net|org))$) { set $host_with_www www.$1; rewrite ^(.*)$ http://$host_with_www$1 permanent; } location / { index index.html index.php; try_files $uri $uri/ @handler; expires 30d; } location /nginx_status { stub_status on; access_log off; #allow 127.0.0.1; #deny all; allow all; } location /app/ { deny all; } location /includes/ { deny all; } location /lib/ { deny all; } location /media/downloadable/ { deny all; } location /pkginfo/ { deny all; } location /report/config.xml { deny all; } location /var/ { deny all; } location /var/export/ { auth_basic "Restricted"; auth_basic_user_file htpasswd; autoindex on; } location /. { return 404; } location @handler { rewrite / /index.php; } location ~ .php/ { rewrite ^(.*.php)/ $1 last; } location ~ .php$ { ## Execute PHP scripts if (!-e $request_filename) { rewrite / /index.php last; } expires off; ## Do not cache dynamic content #fastcgi_pass 127.0.0.1:9000; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 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 MAGE_RUN_CODE default; fastcgi_param MAGE_RUN_TYPE store; fastcgi_buffers 256 16k; fastcgi_buffer_size 32k; include fastcgi_params; ## See /etc/nginx/fastcgi_params } } 

回拨时,这是访问日志的样子:

 85.236.67.1 - - [18/Oct/2011:09:52:03 +0000] "POST /Dibs/Dibs/callback HTTP/1.1" 302 5 "-" "DIBS" 

然后用户被redirect到/Dibs/Dibs/success ,这没有问题。 我试过编辑callback控制器只是echo 1; 所以在函数中的代码没有任何问题。

有没有办法做到/Dibs/Dibs/callback 302redirect/Dibs/Dibs/callback或者我错过了Nginx或PHP中的一些不允许外部POST的configuration?

值得一提的是,我正在使用Vladgh的安装脚本在这里findNginX,MySQL,PHP(与APC和Suhosin) https://github.com/vladgh/VladGh.com-LEMP 。 我在这个callback工作正常的另一台服务器上有完全相同的设置。

可能您将回拨url传递给您的付款服务提供商,而无需预先loginwww,因此您的第一条重写规则将redirect到您的付款服务提供商。 顺便说一句,不要使用这样的重写来redirect到www主机,而是使用不同的server {}块,而不是使用server_name ,请参阅nginx文档 。

我认为你的问题不是用nginx,而是用它提供的PHP应用程序。 在我的本地机器上,当发送一个post请求到testing服务器时,我没有得到一个redirect。 当然,它的configuration与你的稍有不同,但不是很重要。

 server { listen 127.0.0.1:80; server_name www.test.com; root /var/www/test; if ($host ~* ^([a-z0-9\-]+\.(com|net|org))$) { set $host_with_www www.$1; rewrite ^(.*)$ http://$host_with_www$1 permanent; } location / { index index.html index.php; try_files $uri $uri/ @handler; expires 30d; } location /app/ { deny all; } location /includes/ { deny all; } location /lib/ { deny all; } location /media/downloadable/ { deny all; } location /pkginfo/ { deny all; } location /report/config.xml { deny all; } location /var/ { deny all; } location /var/export/ { auth_basic "Restricted"; auth_basic_user_file htpasswd; autoindex on; } location /. { return 404; } location @handler { rewrite / /index.php; } location ~ .php/ { rewrite ^(.*.php)/ $1 last; } location ~ .php$ { ## Execute PHP scripts if (!-e $request_filename) { rewrite / /index.php last; } include snippets/fastcgi-php.conf; fastcgi_pass php; } } 

在文档根目录中,我有以下index.php脚本:

 <?php var_dump($_GET); echo "<hr>"; if (isset($_POST)) { var_dump($_POST); } 

当我构build一个post到/ Dibs / Dibs /callback,我不会redirect。

 curl -d "param1=value1&param2=value2" -X POST "http://127.0.0.1/Dibs/Dibs/callback" -H 'Host: www.test.com' 

这也是说,你得到了两个不同的结果,相同的nginxconfiguration,一个工作,一个没有。 基于这一点,我也会开始寻找redirect的原因。