ec2上的代理apache后无法发布502错误

时间:2018-06-25 15:03:42

标签: node.js apache express graphql mod-proxy

我正在使用具有以下功能的应用程序:

  • Node.js V.8.6.0
  • 快递^ 4.16.3
  • Express Grapql ^ 0.6.12
  • GraphQL ^ 0.13.2
  • CORS ^ 2.8.4

该应用在本地运行正常。但是,当我将我的应用程序安装在ec2服务器上,并将代理apache安装到地址server.example.com上时,我得到了502错误和消息“无法发布”。我使用pm2和pm2-setup来维护node.js进程

我的app / server.js

'use strict'
//first we import our dependencies...
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');

mongoose.Promise = global.Promise;
var schema = require('./src/schema');
var graphqlHTTP = require('express-graphql');

const cors = require('cors');

//and create our instances
const app = express();
const router = express.Router();
const port = process.env.API_PORT || 3001;

//db config -- set your URI from mLab in secrets.js
const mongoDB = 'mongodb://localhost:27017/example';
mongoose.connect(mongoDB, function (err, db) {
 if (err) {
   console.log('Unable to connect to the mongoDB server. Error:', err);
 } else {
   console.log('Connection established to', mongoDB);
 }
});
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));

// Root provides a resolver function for each API endpoint
let root = {
  eventTitle: () => {
    return 'Build a Simple GraphQL Server With Express and NodeJS';
  },
  Title: () => {
    return 'scotch.io';
  }
};


//Use our router configuration when we call /api
app.enable('trust proxy');

const corsOptions = {
origin(origin, callback){
callback(null, true);
},
credentials: true
};

app.use(cors(corsOptions)) 

// GraphqQL server route
app.use('/graphql', graphqlHTTP({
  schema,
  pretty: true,
  graphiql: true
}));

//starts the server and listens for requests
app.listen(port, function() {
  console.log(`api running on port ${port}`);
});

Apache配置

     <VirtualHost *:80>
  ServerName server.example.com
  ErrorLog   ${APACHE_LOG_DIR}/error.log
  CustomLog  ${APACHE_LOG_DIR}/access.log common

  ## Here's our magic
  ProxyRequests Off
  ProxyPreserveHost On
  ProxyVia Full

  <Proxy *>
    #Order deny,allow
    #Allow from all
    Require all granted
  </Proxy>

  <Location /graphql> # no, this closing tag is not a typo
    ProxyPass http://localhost:3001/ retry=1 acquire=3000 timeout=600 Keepalive=On
    ProxyPassReverse http://localhost:3001/

  </Location>
</VirtualHost>

在出现502错误网关之前,我用/ grapql指定了位置。无论如何,我现在收到消息“无法发布”

0 个答案:

没有答案