Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a server setup with Nginx 1.1.4 + PHP-FPM + APC. On this server a Magento installation is running. What I'm having trouble with is that the callback from the payment provider is a POST and Nginx returns a 302 which makes the callback fail.

This is the config file for Nginx for the site:

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;
            #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 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

When the callback is made this is what the access log looks like: - - [18/Oct/2011:09:52:03 +0000] "POST /Dibs/Dibs/callback HTTP/1.1" 302 5 "-" "DIBS"

Then the user gets redirected to /Dibs/Dibs/success which works without a problem. I've tried editing the callback-controller to just echo 1; so that nothing is wrong with the code in the function.

Is there a way to never do a 302 redirect on /Dibs/Dibs/callback or am I missing some configuration in Nginx or PHP that doesn't allow an external POST?

Worth mentioning might be that I'm using Vladgh´s installer script found here for NginX, MySQL, PHP (with APC and Suhosin) I have this exact same setup on another server where the callback works just fine.

share|improve this question

Probably you are passing callback url to your payment provider without www prepended so it gets redirected by your first rewrite rule. BTW, don't use such rewrite to redirect to www host, use different server {} blocks with different server_name instead, see nginx documentation.

share|improve this answer
No, sorry should've mentioned that. The callback url includes http://www. Thank you for the tip on the rewrite, I've updated my configuration that way now. The problem still persists though, and I also tried disabling the forcing of www. – Niklas Modess Oct 18 '11 at 11:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.