【问题标题】:The php file is download instead execute on nginxphp文件是下载而不是在nginx上执行
【发布时间】:2014-10-17 15:20:10
【问题描述】:

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

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 文件?

【问题讨论】:

  • @saurav 你到底是什么意思?
  • 我的配置是对的,我只需要清除浏览器缓存

标签: php symfony nginx configuration


【解决方案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;

        }

}

【讨论】:

  • 这个例子是否适用于 Symfony 框架?或者您只是复制/粘贴您自己的配置? )
  • 但是你的 Symfony 配置坏了!
  • 我的配置是对的,我只需要清除浏览器缓存
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-07-21
  • 1970-01-01
  • 2011-12-30
  • 1970-01-01
  • 2017-06-05
  • 2017-11-16
  • 2017-12-21
相关资源
最近更新 更多