简体   繁体   中英

Nginx Rewrite downloads file

So i have a statistics page for my own website and i wish to do the following;

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

However it seems that the php file gets downloaded, and this is a major issue as this contains my database information. I am using Centos 6 with Php fully installed along with php-fpm.

Here is my virtual.conf file:

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

I have read other peoples questions and the responses however this does not seem to have resolved my issue.

Thanks!

It looks like the location ~ php ... block is in a separate server block. This needs to be inside the server curly brackets to take effect on your stats.mydomain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM