Nginx 重写下载文件

Nginx Rewrite downloads file

所以我有一个自己网站的统计页面,我想做以下事情;

User types: sub.mydomain/u/Username
End result: sub.mydomain/stats.php?player=Username

I want the end result to still show sub.domain/u/Username

但是 php 文件似乎已下载,这是一个主要问题,因为它包含我的数据库信息。我正在使用 Php 完全安装的 Centos 6 以及 php-fpm.

这是我的 virtual.conf 文件:

   location ~ \.php$ {
        try_files $uri =404;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
}

server {
    listen 80;
    server_name stats.mydomain;

    root    /var/www/mydomain/public_html/stats/;

    location / {
        proxy_pass http://mydomain/stats/home.php;
    }
    location /u {
    rewrite ^/u/(.*)$ /stats.php?player= last;
    }
}

我已经阅读了其他人的问题和回复,但这似乎并没有解决我的问题。

谢谢!

看起来 location ~ php ... 块位于单独的服务器块中。这需要在 server 大括号内才能对您的 stats.mydomain.

生效