0

次のディレクトリ構造があります

  • 根/
  • ルート/保護
  • ルート/フレームワーク
  • ルート/バックエンド
  • ルート/バックエンド/保護

最初の Yii アプリケーションは、フレームワーク フォルダーと同じレベルのルート内に直接配置されます。backendフォルダー内にある 2 番目の Yii アプリケーション。どちらも、にある同じフレームワーク フォルダーを使用しますroot

両方のアプリケーションでパス スタイルの URL を使用しています。のようにmydomain.com/controller/action

問題は..

mydomain.com/backend/しかし、 yiiを開こ うとするとbackend、コントローラー名として渡そうとしmydomain.com/index.php、404を返します。しかし、実際には、別のアプリケーションのサブディレクトリです

この問題を解決しようとしました: の内容をroot/index.php次のコードに変更しました:

<?php
if (strpos($_SERVER["REQUEST_URI"], 'backend') !== false) {
    require_once dirname(__FILE__) . '/backend/index.php';
} else {

// change the following paths if necessary
    $yii = dirname(__FILE__) . '/framework/yii.php';
    $config = dirname(__FILE__) . '/protected/config/main.php';

// remove the following lines when in production mode
    defined('YII_DEBUG') or define('YII_DEBUG', true);
// specify how many levels of call stack should be shown in each log message
    defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);

    require_once($yii);
    Yii::createWebApplication($config)->run();

}

それは機能しましたが、すべてのメディア、css ファイルのパスが台無しになりました。内部にある cssbackend/cssは、代わりに mydomain.com/img.jpg を開こうとしますmydomain.com/backend/img.jpg

つまり、私が試したことは正しい解決策ではありません。私のWebサーバーはNGINXで、構成は次のようになります。

server {
    set $host_path "/var/www/mydomain";

    server_name mydomain.com;
    root $host_path;
    set $yii_bootstrap "index.php";

    charset utf-8;

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

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

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


    location ~ \.php$ {
        fastcgi_split_path_info  ^(.+\.php)(.*)$;
        #let yii catch the calls to unexising PHP files
        set $fsn /$yii_bootstrap;
        if (-f $document_root$fastcgi_script_name){
            set $fsn $fastcgi_script_name;
        }
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
      }


    # prevent nginx from serving dotfiles (.htaccess, .svn, .git, etc.)
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }
}
4

1 に答える 1