简体   繁体   English

502代理错误(node.js + express)

[英]502 Proxy Error (node.js + express)

I have a bizarre error that only occurs on my production server. 我有一个奇怪的错误,仅在生产服务器上发生。 This code runs fine on my local development server, but trying to run it on production leaves me with a 502 Proxy Error: 这段代码可以在我的本地开发服务器上正常运行,但是尝试在生产环境中运行它会导致502代理错误:

$.getJSON("/joomla/sales-aggregate?start_date_unix=1416086500", function(sales_data) {
  alert(sales_data);
});

The endpoint for this request is an express app: 此请求的端点是快速应用程序:

app.get('/joomla/sales-aggregate', function (req, res) { 

  var d = new Date();
  var start_date_unix = req.query.start_date_unix || Math.round(d.setDate(d.getDate()-30)/1000);
  console.log(start_date_unix);

  var options = {
    url: 'https://www.client-website.com/api/sales_aggregate.php?start_date_unix=' + start_date_unix,
    port: 80,
    method: 'GET',
    auth: {
      user: "****",
      password: "****"
    }
  };

  request(options, function(err, response, body) {
    res.json(JSON.parse(body));
  });
});

Why would this code work on development, yet return a Proxy Error on production? 为什么此代码可以在开发中起作用,却在生产时返回代理错误?

通过切换到nginx解决了这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM