Google App Engine 502(Bad Gateway)和NodeJS [英] Google App Engine 502 (Bad Gateway) with NodeJS

查看:107
本文介绍了Google App Engine 502(Bad Gateway)和NodeJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用NodeJS,MongoDB(Mongoose作为驱动程序)和ExpressJS的完整Web应用程序。

该项目在我的本地机器上完美运行。今天,我决定把所有东西都搬到生产中。我使用Google App Engine托管我的应用程序,并使用Compose(正式的MongoHQ)托管我的数据库。



App Engine完美地为我的应用程序提供服务,尽管我的API没有似乎工作。我的API服务于 example.com/api ,并且每个请求( GET POST DELETE PUT )都会返回502(错误网关)错误。 p>

我试着在本地机器上运行我的应用程序,同时连接到我的远程MongoDB数据库,并且工作得很好。所以它必须是App Engine或NodeJS的问题,而不是MongoDB。



我试过检查Google Cloud中的所有错误日志,虽然没有错误。 p>

为什么App Engine / NodeJS为我的应用程序的静态内容提供完美的服务,尽管不允许对我的API发出任何请求? >解决方案

502错误的网关通常是Nginx端的错误。不幸的是,这些日志还没有出现在云端日志记录中。



很多时候,问题在于HTTP数据包对于缓冲区或类似的东西来说太大了。您可以看到nginx日志的方式如下所示:




  • 仅使用1个虚拟机。这不是绝对必要的,但是如果你知道你在一台机器上的请求,它可以很容易地调试你的应用程序。您可以通过将其添加到您的app.yaml来完成此操作:




manual_scaling:
实例:1

然后重新部署


  • Switch从Google拥有到自我管理的虚拟机。这可以在云控制台中完成。转到计算引擎实例,单击与App Engine版本匹配的实例名称,您应该看到一个选项将其切换为自我管理。

  • > gcloud compute ssh<实例名称> 以SSH连接到计算机
  • docker ps 查看正在运行的容器。查找名为nginx的容器并获取它的id。

  • 一旦你有一个容器ID,你应该能够 docker exec - 它<容器ID> - cat /var/log/nginx/error.log 。您可能需要 ls 整个日志目录。


    您可能会在这里看到一个错误,这将会提示出现错误的更大提示。

    我知道这比应该更复杂: - 如果您对上述步骤有任何问题,请留下评论。如果您发现错误,并且您不确定如何处理该错误,请发表评论。


    I have a full web application using NodeJS, MongoDB (Mongoose as the driver) and ExpressJS.

    The project works perfectly on my local machine. Today I decided to move everything to production. I'm using Google App Engine to host my application, and Compose (formally MongoHQ) to host my database.

    App Engine servers my application perfectly, although my API does not seem to work. My API is served from example.com/api, and each request (GET, POST, DELETE and PUT) all returns a 502 (Bad Gateway) error.

    I tried running my application on my local machine while connected to my remote MongoDB database and that worked perfectly fine. So it must be a problem with App Engine or NodeJS, not with MongoDB.

    I have tried checking all error logs within Google Cloud, although there are no errors.

    Why is App Engine/NodeJS serving my application's static content perfectly fine, although not allowing any requests to my API?

    解决方案

    502 Bad Gateway is usually an error on the Nginx side. Unfortunately those logs are not surfaced to Cloud Logging, yet.

    A lot of times the problem is that your HTTP packets are too big for the buffers or something similar. The way you can see the nginx log is something like this:

    • Use just 1 VM. This isn't strictly necessary, but a lot of times it makes it easier to debug your application if you know that your requests on the one machine. You can accomplish this by adding this to your app.yaml:

    manual_scaling: instances: 1 then re-deploy

    • Switch the VM from "Google owned" to self-managed. This can be done in the Cloud Console. Go to Compute Engine, instances, click on the instance name that matches the App Engine version, and you should see an option to switch it to self-managed.

    • gcloud compute ssh <instance name> to SSH to the machine

    • docker ps to see your running containers. Look for the container named nginx and grab its id.

    • Once you have a container ID, you should be able to docker exec -it <container id> -- cat /var/log/nginx/error.log. You might want to ls that whole log directory.

    You will likely see an error there which will be a bigger hint as to what's going wrong.

    I know this is way more complicated than it should be :-\ If you have any problems with the steps above, leave a comment. If you do find an error and you're not sure what to do with it, also leave a comment.

    这篇关于Google App Engine 502(Bad Gateway)和NodeJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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