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

I am trying to determine whether file was downloaded successfully or cancelled, following this article http://www.tipstuff.org/2012/08/Nginx-post-action-to-trigger-successfully-download-file.html

I did everything the same, but I am trying to proxy_pass on the same server, not to the different one (like in this example is proxying from nginx to apache), is it even possible?

Looking into access log it acts like it is not giving me any response, i am trying to download a 100mb file at /file.bin, thanks for every suggestion!

Nginx config

server {
            listen 80;
            server_name www.somepage.com;

            access_log /var/log/nginx/www.somepage.com.access_log;
            error_log /var/log/nginx/www.somepage.com.error_log;

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

            location / {
              post_action @afterdownload;
            }

            location @afterdownload {
              proxy_pass http://www.somepage.com/test/test.php?FileName=$request&ClientIP=$remote_addr&body_bytes_sent=$body_bytes_sent&status=$request_completion;
              internal;
            }

            location ~ \.php$ {
              fastcgi_pass   127.0.0.1:9000;
              fastcgi_param  SCRIPT_FILENAME /var/www/www.somepage.com$fastcgi_script_name;
              include fastcgi_params;
            }

}

and /test/test.php to insert values into mysql:

<?php
require_once('../database.php');

mysqli_query($con, "INSERT INTO downloading (info) VALUES ('".mysqli_real_escape_string($con, serialize($_GET))."')");

?>

EDIT: looks like using IP address instead of DNS helped me to see it in the access_log

[01/Sep/2013:12:47:01 +0200] "GET /test/test.php?FileName=GET /file.bin HTTP/1.1&ClientIP=89.176.81.33&body_bytes_sent=14161738&status= HTTP/1.0" 400 166 "-" "-"

but still nothing is being stored in the database, while manually navigating browser to /test/test.php?some=value stores in database...

EDIT: this is what I am getting in error log now:

2013/09/02 11:27:23 [error] 9963#0: *658 upstream sent no valid HTTP/1.0 header while reading response header from upstream, client: 89.176.81.33, server: www.dinoshare.cz, request: "GET /file.bin HTTP/1.1", upstream: "http://94.142.233.120:80/test/test.php?FileName=GET /file.bin HTTP/1.1&ClientIP=89.176.81.33&body_bytes_sent=89244088&status=OK", host: "www.dinoshare.cz"
share|improve this question

1 Answer 1

up vote 2 down vote accepted

your request is somewhat bogus. see your status-code: 400.

check your $request - variable (Everything behind "/test.php?FileName=")

you might want to use $uri instead

share|improve this answer
    
Thanks!!!! I also looked at this once but had no idea that it could not work because of one variable... now it works! –  Wiggler Jtag Sep 3 '13 at 9:10
    
know your docs hahaha –  that guy from over there Sep 3 '13 at 18:10

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.