Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a server setup with Nginx 1.1.4 + PHP-FPM + APC. On this server a Magento 1.5.1.0 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;
            #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
    }
}

When the callback is made this is what the access log looks like:

85.236.67.1 - - [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) https://github.com/vladgh/VladGh.com-LEMP. I have this exact same setup on another server where the callback works just fine.

share|improve this question

1 Answer 1

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

 
discard

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.