dongtao9095 2015-11-08 09:22
浏览 108

nginx提供index.php而不是执行它

I've setup nginx configuration to run php with fcgi on Windows. Here is my config:

server {
    charset utf-8;
    client_max_body_size 128M;

    listen 8888;
    server_name api.domain.local;

    root        /projects/domain.server.new/app/rest/web;
    index       index.php;

    error_log   /webservers/nginx/logs/api.domain.local.error.log;

    location / {
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php?$args;
    }

    #uncomment to avoid processing of calls to non-existing static files by Yii
    location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
        try_files $uri =404;
    }
    error_page 404 /404.html;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass   127.0.0.1:9123;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ //.(ht|svn|git) {
        deny all;
    }
}

I've checked if fcgi server is running and it's all OK:

E:\Webservers\Nginx>netstat -aon | findstr :9123
  TCP    127.0.0.1:9123         0.0.0.0:0              LISTENING       2644

Then I request the file using curl to prevent file caching:

$ curl -i localhost:8888

HTTP/1.1 200 OK
Server: nginx/1.6.1
Date: Sun, 08 Nov 2015 09:15:20 GMT
Content-Type: application/octet-stream
Content-Length: 960
Last-Modified: Tue, 27 Oct 2015 17:33:50 GMT
Connection: keep-alive
ETag: "562fb57e-3c0"
Accept-Ranges: bytes

<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/bootstrap.php');
require(__DIR__ . '/../config/bootstrap.php');

$config = yii\helpers\ArrayHelper::merge(
    require(__DIR__ . '/../../common/config/main.php'),
    require(__DIR__ . '/../../common/config/main-local.php'),
    require(__DIR__ . '/../config/main.php'),
    require(__DIR__ . '/../config/main-local.php')
);

$application = new yii\web\Application($config);
$application->run();

And it outputs files content instead of running it. I've tried several solutions offered in other topics:

  1. Changed default_type application/octet-stream to default_type text/html in the config
  2. Changed location ~ / .php$ to location ~* / .php$

But it doesn't work. How can I debug it?

  • 写回答

2条回答 默认 最新

  • doujia4619 2015-11-08 09:36
    关注

    The

    location ~ /.php$ {
    

    configuration line does not look correct. It means: a location that ends with a / character followed by any character followed by php. Eg: foobar/zphp.

    What you meant probably is

    location ~ \.php$ {
    

    which means: a location that ends with .php. Eg: /index.php

    The same fix would be applied to the other section where you also confused the \ with /.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器