2015-11-08 33 views
0

我已經設置了nginx配置以在Windows上運行帶有fcgi的php。下面是我的配置:nginx服務於index.php而不是執行它

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

如果FCGI服務器運行我檢查了,這一切都OK:

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

然後我要求使用curl,以防止文件緩存文件:

$ 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(); 

它輸出文件內容而不是運行它。我試過的其他主題提供了幾個解決方案:

  1. 在配置
  2. 改變location ~/.php$改變default_type application/octet-streamdefault_type text/htmllocation ~*/.php$

但它不工作。我該如何調試它?

回答

1

location ~ /.php$ { 

配置行看起來並不正確。這意味着:以/後跟任何字符後跟php結尾的位置。例如:foobar/zphp

你大概的意思是

location ~ \.php$ { 

這意味着:與.php結束的位置。例如:/index.php

相同的修復方法將應用於其他部分,在此部分中,您還將\/混淆。

+0

謝謝,我更新了我的問題與修復配置,但該文件仍然返回。如果還有其他遺漏,你可以看看嗎? –

+0

@Maximus在'〜'後面的對應行中有''怪異的'*'。甚至不確定它在那裏是有意義的。 – zerkms

+0

我已經從那裏刪除它,stil不起作用:( –

相關問題