3

I have setup a server that uses nginx as a reverse proxy for an express js application.

This is what my nginx config file looks like located at /etc/nginx/sites-available/default

upstream app {
  server domainIP:80;
  server domainIP:3000;
}

server {

listen 80;
server_name domain.com;

    location / {

    proxy_set_header   X-NginX-Proxy    true;
    proxy_set_header Host $host;
    proxy_pass http://app;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_cache_bypass $http_upgrade;
    proxy_set_header   X-Real-IP            $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_redirect off;
    proxy_read_timeout 150;

    }
}

I can access my site and all of its pages with no problems.

However I have a contact form that uses nodemailer to send an email to my personal email with the following set up

var transporter = nodemailer.createTransport({
    service: 'Gmail',
    auth: {
        user: 'email@gmail.com',
        pass: 'myPass'
    }
});

router.post('/contact', function(req, res, next) {

   // send mail with defined transport object 
   transporter.sendMail(mailOptions, function(error, info){
   if(error){
      res.status(500);
      res.render('index', {title: "Rhys Austin", error: error});
      res.end();
      return console.log(error);
   }
      res.status(200);
      res.render('index', {title: "Rhys Austin"});
      return;
   });


});

The mailOptions variable is defined.

Whenever I fill the form on a local setup, the email successful sends and I can see it in my gmail inbox.

However, on the production server the request hangs, which resulted in a 504 time-out error which then changed to a 502 bad gateway error when I added proxy_read_timeout 150 to the nginx configuration.

I think it may be something to do with the nginx configuration, but I cannot figure it out. How can I get my email to successful send on my production server?

R. Austin
  • 31
  • 4

0 Answers0