0

ローカル PC でアプリケーションを実行しようとしています。クラウド上ではすべて問題なく動作し、以下のコードで MongoDB に接続します。

    $services_json = json_decode(getenv("VCAP_SERVICES"),true);
$mongo_config = $services_json["mongodb-1.8"][0]["credentials"];

// Generally will be localhost if you're querying from the machine that Mongo is installed on
$config['mongo_host'] = $mongo_config["hostname"];

// Generally will be 27017 unless you've configured Mongo otherwise
$config['mongo_port'] = $mongo_config["port"];

// The database you want to work from (required)
$config['mongo_db'] = $mongo_config["db"];

// Leave blank if Mongo is not running in auth mode
$config['mongo_user'] = $mongo_config["username"];
$config['mongo_pass'] = $mongo_config["password"];

しかし、ローカル pc から vcap_services を取得できないため、接続に定数値を使用して、アプリを appfog のリモート mongo サーバーに接続しています。

    // Generally will be localhost if you're querying from the machine that Mongo is installed on
$config['mongo_host'] = "***";

// Generally will be 27017 unless you've configured Mongo otherwise
$config['mongo_port'] = "***";

// The database you want to work from (required)
$config['mongo_db'] = "db";

// Leave blank if Mongo is not running in auth mode
$config['mongo_user'] = "***";
$config['mongo_pass'] = "***";

しかし、アプリを実行しようとすると、次のhttp://localhost/my-appエラーが発生しました。

Unable to connect to MongoDB: Failed to connect to: ***: Connection timed out

何が問題になる可能性がありますか?

個人情報保護のため数値は削除しております。

4

1 に答える 1

1

VCAP 変数を使用せずに、localhost ではなく実際のサーバーに接続しようとしましたか? AppFog は、VCAP 変数なしで接続する権限を与えないか、手動で取得した値に問題がある可能性があります。

これは承認の問題だと思います。対応できない場合は、別のクラウド サービスをお試しください。これが唯一の解決策ではありません。

于 2013-10-03T14:33:45.823 に答える