2

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.server.com, 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.server.com"
0

1 Answer 1

2

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

2
  • Thanks!!!! I also looked at this once but had no idea that it could not work because of one variable... now it works! Sep 3, 2013 at 9:10
  • know your docs hahaha Sep 3, 2013 at 18:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .