如何正确配置Nginx for PHP(Yii框架和Zurmo)

时间:2013-07-06 12:15:22

标签: php configuration yii nginx path

我正在尝试在我的本地计算机(Win8x64)上设置Zurmo CRM。在安装了我想要开始实际安装的所有要求之后。问题是似乎路径没有正确地从NGinx传递到FastCGI PHP。这是我的Nginx服务配置:

server {

    listen       80;
    server_name  zurmo.local;
    root         html/zurmo.local;
    set $index   "index.php";

    charset utf-8;

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

    location ~ ^/(protected|framework|themes/\w+/views) {
        deny  all;
    }

    location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
        try_files $uri =404;
    }

    location ~ \.php {

        fastcgi_split_path_info  ^(.+\.php)(.*)$;

        set $fsn /$index;
        if (-f $document_root$fastcgi_script_name){
            set $fsn $fastcgi_script_name;
        }

        fastcgi_pass   127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fsn;
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fsn;
    }

    location ~ /\.ht {
        deny  all;
    }
}

因此,当我调用zurmo.local(添加到hosts文件)时,我得到“此网页有一个重定向循环”,其URI看起来像http://zurmo.local/app/app/ [...] /app/app/index.php如果不是{ {1}}我评论$document_root$fsnPATH_INFO,而不是PATH_TRANSLATED,其URI看起来像No input file specified.

进一步了解,当我添加http://zurmo.local/app/app/index.php时,Nginx access_log html/zurmo.local/logs/access.log;会向我显示以下内容:error.log。如您所见,目录分隔符不一致。

最后一点,我的Nginx主目录位于[timestamp] [emerg] 4064#3660: CreateFile() "[path to stack]\nginx/html/zurmo.local/logs/access.log" failed (3: The system cannot find the path specified),这实际上是nginx/html的smlink。这纯粹是为了保持我的文件结构适合我的日常工作

如何正确配置Nginx才能继续(使用Zurmo安装)?

2 个答案:

答案 0 :(得分:2)

我知道这是一个老问题,但这是我为使nginx + zurmo工作所做的工作。

server {
    listen       80;
    server_name  zurmo.local;
    root         /home/www/zurmo.local;
    access_log   /var/log/nginx/zurmo.access.log main;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ ^/(protected|framework|themes/\w+/views) { deny all; }
    location ~ /\. { deny all; access_log off; log_not_found off; }
    location = /favicon.ico { log_not_found off; access_log off; }
    location ~ \.(js|css|png|jpg|gif|ico|pdf|zip|rar)$ {
        try_files $uri =404;
    }

    location ~ \.php {
        fastcgi_split_path_info  ^(.+\.php)(.*)$;

        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;

        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;

        fastcgi_read_timeout 600s;
        fastcgi_send_timeout 600s;
    }
}

答案 1 :(得分:0)

我认为您if()块中不需要*.php语句。在我的nginx设置中,这就是我所需要的:

# Process PHP files
location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    # Include the standard fastcgi_params file included with nginx
    include fastcgi_params;

    fastcgi_param  PATH_INFO        $fastcgi_path_info;
    fastcgi_index index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

    fastcgi_pass 127.0.0.1:9000;
}