节点/mysql/nginx-502错误的网关 [英] node/mysql/nginx - 502 bad gateway

查看:131
本文介绍了节点/mysql/nginx-502错误的网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用nginx在ubuntu服务器14.04上运行节点应用程序.我有一个mysql数据库,该数据库最初在其他服务器上运行.一切正常,但为了调整性能,我将其移至同一服务器上,尝试通过本地主机连接时遇到错误.我正在使用具有以下配置的 node-mysql :

I'm running a node app on ubuntu server 14.04 with nginx. I have a mysql database, which was initially running on a different server. Everything worked fine, but in an effort to tune performance I moved it onto the same server and I'm getting an error trying to connect through localhost. I'm using node-mysql with the following configuration:

host: 'localhost',
user: 'root',
password: 'xxx',
database: 'xxx'

在初始安装后,我还没有对mysql进行任何更改,只是创建了一个转储文件并运行它来创建数据库.

I haven't really changed anything with mysql after the initial installation, simply created a dump file and ran it to create the database.

每当我的应用程序访问数据库时,我都会收到以下错误消息:

I get the following error whenever my app hits the database:

502(错误网关)

502 (Bad Gateway)

我进行了搜索,但是发现的所有内容都与PHP有关.

I've searched around but everything I find on this is PHP related.

更新: 检查了pm2日志(使用pm2运行节点),并显示以下错误:

Update: Checked the pm2 logs (using pm2 to run node) and it's giving the following error:

ECONNREFUSED 127.0.0.1:3306

ECONNREFUSED 127.0.0.1:3306

我需要做些什么来打开它吗?

Is there something I need to do to open this up?

推荐答案

在通过注释向正确的方向提供帮助并找到了真正的错误之后,我能够找到解决方法

After being helped in the right direction via the comments and finding the real error, I was able to find the solution here. Needed to supply the mysql socket path in the node-mysql configuration.

host: 'localhost',
user: 'root',
password: 'xxx',
database: 'xxx',
socketPath: '/var/run/mysqld/mysqld.sock'

这篇关于节点/mysql/nginx-502错误的网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆