我是新来的Heroku & Node,所以请容忍我。我将我的工作聊天应用程序(在本地主机上)部署到Heroku,但无法打开Heroku应用程序。
有人能帮我解决这个问题吗?
我看了一些类似的关于堆栈溢出的问题,并且做了heroku config:add REDISCLOUD_URL='redis_cloud_url'和heroku config:add NODE_ENV='production',但是这些问题都没有起作用。
这是我的heroku日志。
2015-04-11T19:42:35.568690+00:00 heroku[api]: Deploy 0244dd7 by MYMAIL@gmail.com
2015-04-11T19:42:38.004491+00:00 heroku[web.1]: Starting process with command `node app.js`
2015-04-11T19:42:39.182617+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2015-04-11T19:42:39.182639+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
2015-04-11T19:42:39.793252+00:00 app[web.1]: events.js:85
2015-04-11T19:42:39.793258+00:00 app[web.1]: throw er; // Unhandled 'error' event
2015-04-11T19:42:39.793260+00:00 app[web.1]: ^
2015-04-11T19:42:39.793262+00:00 app[web.1]: Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
2015-04-11T19:42:39.793264+00:00 app[web.1]: at RedisClient.on_error (/app/node_modules/redis/index.js:196:24)
2015-04-11T19:42:39.793266+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/redis/index.js:106:14)
2015-04-11T19:42:39.793268+00:00 app[web.1]: at Socket.emit (events.js:107:17)
2015-04-11T19:42:39.793270+00:00 app[web.1]: at net.js:459:14
2015-04-11T19:42:39.793271+00:00 app[web.1]: at process._tickCallback (node.js:355:11)
2015-04-11T19:42:40.546881+00:00 heroku[web.1]: State changed from starting to crashed发布于 2015-04-12 06:08:41
好的,我知道问题所在,问题是你使用的是redis云,所以redis是而不是运行在127.0.0.1上
看看Heroku上的正式文件;您不能将REDISCLOUD_URL设置为redis_cloud_url,您必须让Heroku将其设置为您的帐户‘s REDISCLOUD_URL,这样您就可以在终端中这样做了。
heroku config:get REDISCLOUD_URL它应该归还像这样的东西;
http://rediscloud:password@hostname:port如果它返回一些没有这种格式的东西,那么你的应用程序就没有正确地配置/激活这个插件。
连接到redis的代码应该如下所示:
var redis = require('redis');
var url = require('url');
var redisURL = url.parse(process.env.REDISCLOUD_URL);
var client = redis.createClient(redisURL.port, redisURL.hostname, {no_ready_check: true});
client.auth(redisURL.auth.split(":")[1]);发布于 2019-05-07 12:26:36
我用的是Heroku Redis,而不是Redis,我也有过这样的问题。但是,我通过改变Redis客户端初始化的方式解决了这个问题,之前我有以下代码:
const
redisOptions = require('./redisOptions'),
redis = require('redis'),
redisClient = redis.createClient(redisOptions);现在,我从redisOptions中删除了url参数,然后将它添加到createClient方法中,即:
const
redisOptions = require('./redisOptions'),
redis = require('redis'),
redisClient = redis.createClient(REDIS_URL, redisOptions);然后错误被修正了。我真的不知道为什么它在我的本地环境中没有任何问题,但是我需要对Heroku进行这个修复。
https://stackoverflow.com/questions/29582690
复制相似问题