2013-05-28 50 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', 
        ... 
    );