Nginx post_action、proxy_pass、追蹤下載文件

Nginx post_action、proxy_pass、追蹤下載文件

我正在嘗試根據本文確定文件是否已成功下載或取消http://www.tipstuff.org/2012/08/Nginx-post-action-to-trigger-successively-download-file.html

我做的一切都是一樣的,但我試圖在同一台伺服器上 proxy_pass,而不是不同的伺服器(就像在這個例子中從 nginx 代理到 apache),這可能嗎?

查看訪問日誌,它就像沒有給我任何回應,我正在嘗試在 /file.bin 下載一個 100mb 文件,感謝您的每一個建議!

Nginx 設定

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

}

和 /test/test.php 將值插入 mysql:

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

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

?>

編輯:看起來使用 IP 位址而不是 DNS 幫助我在 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 "-" "-"

但在手動將瀏覽器導航到 /test/test.php?some=value 儲存在資料庫中時,資料庫中仍然沒有儲存任何內容...

編輯:這就是我現在在錯誤日誌中收到的內容:

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"

答案1

你的要求有點虛假。查看您的狀態代碼:400。

檢查您的 $request - 變數(“/test.php?FileName=”後面的所有內容)

你可能會想使用$uri反而

相關內容