我正在尝试确定文件是否已成功下载或被取消,请按照本文操作http://www.tipstuff.org/2012/08/Nginx-post-action-to-trigger-successfully-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"