我在错误日志中收到此错误: 2019/01/31 22:08:09 [错误] 22406#22406:* 113上游超时(110:连接超时),同时从上游读取响应头,客户端:107.11.24.140,服务器:isitestack.com,请求: “ POST / send HTTP / 1.1”,上游:“ http://127.0.0.1:3000/send”,主机:“ isitestack.com”,引荐来源网址:“ https://isitestack.com/”
我在数字海洋上使用mailgun,nodemailer,nodejs和nginx来提供我的应用程序。现在在isitestack.com上可以正常显示,但是联系表单不起作用,并且在我测试表单并发送请求时显示504超时错误。这些请求在本地服务器上运行良好。我包括我的节点app.js文件和nginx / etc / nginx / sites-available / default文件,因为我认为问题出在其中之一。任何帮助将不胜感激。
const express = require('express');
const bodyParser = require('body-parser');
const exphbs = require('express-handlebars');
const path = require('path');
const nodemailer = require('nodemailer');
const dotenv = require('dotenv').config();
const app = express();
//view engine setup
app.engine('handlebars', exphbs());
app.set('view engine', 'handlebars');
//static folder
app.use('/public', express.static(path.join(__dirname, 'public')));
//body parser middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//routes
app.get('/', (req, res) => {
res.render('contact');
});
app.post('/send', (req, res) => {
const output = `
<p>You have a new request from iSiteStack</p>
<h3>Contact Details</h3>
<ul>
<li>Name: ${req.body.name}</li>
<li>Email: ${req.body.email}</li>
</ul>
<h3>Message</h3><p>${req.body.message}</p> `;
let transporter = nodemailer.createTransport({
host: "smtp.mailgun.org",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: process.env.NODEMAILER_USER,
pass: process.env.NODEMAILER_PASS
},
tls:{
rejectUnauthorized: false
}
});
// setup email data with unicode symbols
let mailOptions = {
from: '"iSiteStack LLC" <postmaster@isitestack.com>', // sender address
to: "lazav2021@gmail.com", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world?", // plain text body
html: output // html body
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log("Message sent: %s", info.messageId);
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
res.render('contact', {msg: "Your email has been sent. Thanks for contacting me. I will respond as soon as possible."});
});
});
app.listen(3000, () => console.log('server started....'));
............................................... ..........................
nginx /etc/nginx/sites-available/default file below
............................................... ..........................
server {
root /var/www/html;
server_name isitestack.com www.isitestack.com;
location / {
proxy_pass http://127.0.0.1:3000/;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/isitestack.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/isitestack.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.isitestack.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = isitestack.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name isitestack.com www.isitestack.com;
return 404; # managed by Certbot
}