【问题标题】:Nginx Rewrite downloads fileNginx 重写下载文件
【发布时间】:2016-07-31 20:16:48
【问题描述】:

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

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 文件被下载了,这是一个主要问题,因为它包含我的数据库信息。我正在使用 Centos 6,完全安装了 Php 以及 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=$1 last;
    }
}

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

谢谢!

【问题讨论】:

    标签: php nginx centos6


    【解决方案1】:

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

    【讨论】:

    • 天哪!非常感谢!
    猜你喜欢
    • 2015-09-12
    • 1970-01-01
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多