Configuration nginx配置。Yii项目位于单独目录中[不在根目录中]

Configuration nginx配置。Yii项目位于单独目录中[不在根目录中],configuration,yii,nginx,subdirectory,Configuration,Yii,Nginx,Subdirectory,我花了6个多小时解决这个问题 我有nginx/1.2.7服务器和127.0.0.1:9000上的php fpm。 我有基本nginx配置: server { listen 80; server_name example.org www.example.org; index index.php index.html; access_log /srv/www/example.org/logs/access.log; error_log /srv/www/e

我花了6个多小时解决这个问题

我有nginx/1.2.7服务器和127.0.0.1:9000上的php fpm。 我有基本nginx配置:

server
{
    listen 80;
    server_name example.org www.example.org;

    index index.php index.html;

    access_log /srv/www/example.org/logs/access.log;
    error_log /srv/www/example.org/logs/error.log;

    location /
    {
        root /var/www/html/example.org/public_html;
        try_files $uri $uri/ /index.php;

        location ~ \.php$
        {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    }
而且效果很好!所有的php文件都能正常工作

但我有一些单独的yii项目,需要在主根文件夹之外的其他文件夹中执行。 我在底部添加了此配置:

其中/srv/www/example.org/yiitest-它是yiitest项目的根目录(其中包含“受保护”文件夹和其他文件夹)

但它不起作用。我找到了“找不到文件”。 我能得到的最大值是:example.org/yiitest/主页运行良好。 如果我去example.org/yiitest/site/contact/我会得到找不到的文件:(

我不明白,如何在服务器的单独子目录中正确设置yii项目

  • 创建符号链接

    cd /var/www/html/example.org/public_html
    ln -s ../yiitest/public yiitest
    
  • 配置nginx

    root /var/www/html/example.org/public_html;
    
    location / {
        ...
    }
    
    location /yiitest/ {
        index    index.php;
    
        # front end
        if (!-e $request_filename) {
            rewrite ^(.*)$ /yiitest/index.php last;
            break;
        }
    }
    
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1: 9000;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO        $fastcgi_script_name;
        include fastcgi_params;
    }
    
  • 然后配置yii框架。您应该在配置中设置“basePath”:

    <?php
    return array(
        'basePath' => 'yiitest',
        ...
    );
    
    
    
  • 创建符号链接

    cd /var/www/html/example.org/public_html
    ln -s ../yiitest/public yiitest
    
  • 配置nginx

    root /var/www/html/example.org/public_html;
    
    location / {
        ...
    }
    
    location /yiitest/ {
        index    index.php;
    
        # front end
        if (!-e $request_filename) {
            rewrite ^(.*)$ /yiitest/index.php last;
            break;
        }
    }
    
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1: 9000;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO        $fastcgi_script_name;
        include fastcgi_params;
    }
    
  • 然后配置yii框架。您应该在配置中设置“basePath”:

    <?php
    return array(
        'basePath' => 'yiitest',
        ...
    );
    

    我面临着同样的问题。你找到解决办法了吗?我面临着同样的问题。你找到解决办法了吗?