Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP-FPM and Nginx rewrite causing download [closed]

Tags:

php

nginx

I have an Nginx HTTP server with PHP-FPM set up and almost everything works fine. I want to be able to go to path/to/file and it give me index.php?url=path/to/file, which it does. However, it downloads the actual PHP, it won't execute it in the browser. I'm not sure what is causing this.

Nginx configuration:

server {
    listen 80;
    server_name sandbox.domain.tld;
    access_log /path/to/domain/log/sandbox.access.log;
    error_log /path/to/domain/log/sandbox.error.log;

    location / {
        root /path/to/sandbox;
        index index.php;

        if (!-e $request_filename) {
            rewrite ^/beta/(.+)$ /beta/index.php?url=$1 break;
        }
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include /usr/local/nginx/conf/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /path/to/sandbox$fastcgi_script_name;
    }
like image 757
will Avatar asked Dec 20 '12 21:12

will


1 Answers

Try changing

rewrite ^/beta/(.+)$ /beta/index.php?url=$1 break; to

rewrite ^/beta/(.+)$ /beta/index.php?url=$1 last; break;

Which should get nginx to re-read the URI and process it accordingly.

like image 74
plasmid87 Avatar answered Sep 20 '22 14:09

plasmid87