下载php文件而不是在nginx上执行

时间:2014-08-24 07:40:41

标签: php symfony nginx configuration

我使用Symfony服务器的Nginx配置:

server {
    server_name cmf.localhost www.cmf.localhost;
    root /mnt/hgfs/www/cmf/web;

    error_log /var/log/nginx/cmf.error.log;
    access_log /var/log/nginx/cmf.access.log;

    # strip app.php/ prefix if it is present
    rewrite ^/app_dev\.php/?(.*)$ /$1 permanent;

    location = /libs/ckfinder/core/connector/php/connector.php {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }

    location / {
        index app_dev.php app.php;
        try_files $uri @rewriteapp;
    }

    location @rewriteapp {
        rewrite ^(.*)$ /app_dev.php/$1 last;
    }

    # pass the PHP scripts to FastCGI server from upstream phpfcgi
    location ~ ^/(app|app_dev|config)\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }
}

并且效果很好,但我还需要执行/libs/ckfinder/core/connector/php/connector.php。现在,当我尝试执行它们时,只需下载。

如何将Nginx配置为执行/libs/ckfinder/core/connector/php/connector.php文件?

1 个答案:

答案 0 :(得分:-1)

server {
        listen   80;


        root /usr/share/nginx/www;
        index index.php index.html index.htm;

        server_name example.com;

        location / {
                try_files $uri $uri/ /index.html;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;
        }

        # pass the PHP scripts to FastCGI server listening on the php-fpm socket
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

        }

}