【问题标题】:Connect to MongoDB on Appfog from localhost从本地主机连接到 Appfog 上的 MongoDB
【发布时间】:2013-08-26 08:24:14
【问题描述】:

我正在尝试在本地电脑上运行我的应用程序。在云上一切看起来都很好,它可以工作并使用以下代码连接到 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"];

但由于我无法从本地电脑获取 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

可能是什么问题?

* 值被删除以保护隐私。

【问题讨论】:

  • 你能连接到http://localhost:28017/吗?
  • 是的,但主要问题不在于 localhost。我有另一个像 10.*.*.* 这样的主机,我需要从本地连接到 appfog。

标签: php codeigniter mongodb remote-access appfog


【解决方案1】:

您是否尝试在不使用 VCAP 变量而不是在本地主机上而是在实际服务器上进行连接?如果没有 VCAP 变量,AppFog 可能无法授权进行连接,或者您手动获取的值可能有问题。

我认为这是一个授权问题。如果您无法处理,请尝试其他云服务。这不是唯一的解决方案。

【讨论】:

  • 已经更改了我正在使用的服务。 AppFog 不想帮助我,但我认为您可能是对的。我使用的服务为我提供了确切的值,而不是来自 VCAP 服务。
猜你喜欢
  • 2018-04-11
  • 2018-04-19
  • 1970-01-01
  • 2019-12-03
  • 1970-01-01
  • 1970-01-01
  • 2018-01-10
  • 2023-03-16
  • 2017-09-09
相关资源
最近更新 更多