2013-05-28 49 views
1

我花了6个多小时在这个麻烦。nginx配置。 Yii项目在单独的目录[不在根目录]

我有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项目的根目录(与“保护”文件夹等里面)。

location /yiitest 
    { 
     root /srv/www/example.org/yiitest; 
     try_files $uri $uri/ /index.php?$args; 

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

但它不起作用。我有'文件未找到'。 我能得到的最大值是:example.org/yiitest/主页面正常工作。 如果我去example.org/yiitest/site/contact/我会得到文件未找到。 :(

我不明白,如何正确安装警予项目在服务器的单独的子目录。

+1

我面临着同样的问题的种类。你有没有找到解决方案? –

回答

1
  1. 创建符号链接

    cd /var/www/html/example.org/public_html 
    ln -s ../yiitest/public yiitest 
    
  2. 配置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; 
    } 
    
  3. 然后配置yii框架,你应该在你的config中设置'basePath':

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