在GAE中部署时出现502错误的网关 [英] 502 Bad Gateway while deploying in GAE

查看:67
本文介绍了在GAE中部署时出现502错误的网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Google App Engine中部署我的nodejs应用程序.但是当我运行

I am trying to deploy my nodejs application in Google App Engine. But I keep on getting 502 Bad Gateway when I run

$ gcloud app browse

这是我的文件结构

->project
  |___node_modules
  |___models
  |___routes
  |___index.js
  |___app.yaml
  |___package.json
  |___package.lock.json
  |___public
      |___index.html
      |___js 

这是我的app.yaml文件

This is my app.yaml file

env: flex
runtime: nodejs
threadsafe: true
manual_scaling:
  instances: 1

# Handle the main page by serving the index page.
handlers:
- url: /
  static_files: public/index.html
  upload: public/index.html

- url: /(.*)
  static_files: public/\1
  upload: public/(.*)

# Recommended file skipping declaration from the GAE tutorials
skip_files:
  - ^(.*/)?app\.yaml
  - ^(.*/)?app\.yml
  - ^(.*/)?#.*#
  - ^(.*/)?.*~
  - ^(.*/)?.*\.py[co]
  - ^(.*/)?.*/RCS/.*
  - ^(.*/)?\..*
  - ^(.*/)?tests$
  - ^(.*/)?test$
  - ^test/(.*/)?
  - ^COPYING.LESSER
  - ^README\..*
  - \.gitignore
  - ^\.git/.*
  - \.*\.lint$
  - ^fabfile\.py
  - ^testrunner\.py
  - ^grunt\.js
  - ^node_modules/(.*/)?

注意:我正在端口8080上运行,并在package.json中包含了"start":"node index.js"

Note: I am running on port 8080 and have included "start" : "node index.js" in package.json

推荐答案

我发现了我的错误.它在index.js文件中.以前:

I found my mistake. It was in the index.js file. Previously:

const port = process.env.PORT || 8080;
app.listen(port, "localhost",()=>{
    console.log("Server running at port " + port);
});

我必须替换为:

const port = process.env.PORT || 8080;
app.listen(port, ()=>{
    console.log("Server running at port " + port);
});

这篇关于在GAE中部署时出现502错误的网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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