Question

nginx 502 Bad Gateway with parse & send grid

Posted May 10, 2016 5.8k views
Nginx

Hey guys,

I am trying to migrate my parse application over to digital ocean and followed this guide :

https://www.digitalocean.com/community/tutorials/how-to-migrate-a-parse-app-to-parse-server-on-ubuntu-14-04

Everything works perfectly fine until I get to the very end Test Parse Server ( Executing Example Cloud Code ) section

I tested the cloud code for the sample cloud code that was provided in the tutorial :

Parse.Cloud.define('hello', function(req, res) {
  res.success('Hi');
});

so I got a Hi back in my browser as well as in postman. Then I test the function that uses sendgrid’s service to send emails :

var sendgrid = require("sendgrid");
sendgrid.initialize("sendgridAccountSid", "sendgridAuthToken");

Parse.Cloud.define("mySendGridFunction", function(request, response) {
  sendgrid.sendEmail({
    to: "community@parse.com",
    from: "sendgrid@parse.com",
    subject: "Hello from Cloud Code!",
    text: "Using Parse and SendGrid is great!"
  }, {
    success: function(httpResponse) { response.success("Email sent!"); },
    error: function(httpResponse) { response.error("Uh oh, something went wrong"); }
  });
});

now this function returns me a nginx 502 Error sometimes and sometimes it returns me with internal server error

<html>
    <head>
        <title>502 Bad Gateway</title>
    </head>
    <body bgcolor="white">
        <center>
            <h1>502 Bad Gateway</h1>
        </center>
        <hr>
        <center>nginx/1.4.6 (Ubuntu)</center>

    </body>

</html>
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->

I went into my droplet to view the error.log file for nginx and this is the error I get there :

2016/05/09 20:15:26 [error] 31786#0: *68 connect() failed (111: Connection refused) while connecting to upstream, client: 159.203.7.41, server: test.pacecouriers.com, request: "POST /parse/functions/mySendGridFunction HTTP/1.1", upstream: "http://127.0.0.1:1337/functions/mySendGridFunction", host: "test.pacecouriers.com"

I kept looking around and I somewhere in between got a 301 parmanently moved error too and now my calls to the hello function are also not working and return me a 502 Bad Gateway error on all the requests to my nginx that I set up for my parse app on the droplet. Can someone please help me.

edited by kamaln7

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi Tanzeelrana,

Did you find a solution ?

I have the same issues

Submit an Answer