我正在从在AWS上运行RHEL 8的计算机上运行基于apache2的SSL服务器。我正在尝试在此服务器上部署一个Facebook Webhook。我正在使用curl请求对此进行手动测试。当我通过HTTP将请求放入时,其行为与预期的一样。但是,通过HTTPS发出请求时,出现以下错误消息:
curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number
我需要使其在HTTPS上运行,因为Facebook不允许仅HTTP连接。
谢谢您,任何建议都是令人惊奇的-如果我对此提出的要求很抱歉,这是我的第一个问题。
Webhook的代码如下:
// Imports dependencies and set up http server
const
express = require('express'),
bodyParser = require('body-parser'),
app = express().use(bodyParser.json()); // creates express http server
// Sets server port and logs message on success
app.listen(process.env.PORT || 1337, () => console.log('webhook is listening'));
// Creates the endpoint for our webhook
app.post('/webhook', (req, res) => {
let body = req.body;
// Checks this is an event from a page subscription
if (body.object === 'page') {
// Iterates over each entry - there may be multiple if batched
body.entry.forEach(function(entry) {
// Gets the message. entry.messaging is an array, but
// will only ever contain one message, so we get index 0
let webhook_event = entry.messaging[0];
console.log(webhook_event);
});
// Returns a '200 OK' response to all requests
res.status(200).send('EVENT_RECEIVED');
} else {
// Returns a '404 Not Found' if event is not from a page subscription
res.sendStatus(404);
}
});
// Adds support for GET requests to our webhook
app.get('/webhook', (req, res) => {
// Your verify token. Should be a random string.
let VERIFY_TOKEN = "duckgoesquack"
// Parse the query params
let mode = req.query['hub.mode'];
let token = req.query['hub.verify_token'];
let challenge = req.query['hub.challenge'];
// Checks if a token and mode is in the query string of the request
if (mode && token) {
// Checks the mode and token sent is correct
if (mode === 'subscribe' && token === VERIFY_TOKEN) {
// Responds with the challenge token from the request
console.log('WEBHOOK_VERIFIED');
res.status(200).send(challenge);
} else {
// Responds with '403 Forbidden' if verify tokens do not match
res.sendStatus(403);
}
}
});
我尝试更新我的apache conf文件-virtualhosts部分如下:
NameVirtualHost *:80
<VirtualHost *:443>
ServerName lloydarnoldtestapps.tk
DocumentRoot /var/www/lloydarnoldtestapps.tk
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/lloydarnoldtestapps.tk/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/lloydarnoldtestapps.tk/privkey.pem
</VirtualHost>
<VirtualHost *:80>
ServerName lloydarnoldtestapps.tk
DocumentRoot /var/www/lloydarnoldtestapps.tk
</VirtualHost>
<VirtualHost *:443>
ServerName www.lloydarnoldtestapps.tk
ServerAlias *.lloydarnoldtestaps.tk
DocumentRoot /var/www/lloydarnoldtestapps.tk
SSLCertificateFile /etc/letsencrypt/live/lloydarnoldtestapps.tk/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/lloydarnoldtestapps.tk/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
<VirtualHost *:1337>
ServerName lloydarnoldtestapps.tk
DocumentRoot /var/www/lloydarnoldtestapps.tk
SSLCertificateFile /etc/letsencrypt/live/lloydarnoldtestapps.tk/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/lloydarnoldtestapps.tk/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
<VirtualHost *:80>
ServerName www.lloydarnoldtestapps.tk
DocumentRoot /var/www/lloydarnoldtestapps.tk
</VirtualHost>
<VirtualHost *:1337>
ServerName www.lloydarnoldtestapps.tk
DocumentRoot /var/www/lloydarnoldtestapps.tk
SSLCertificateFile /etc/letsencrypt/live/lloydarnoldtestapps.tk/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/lloydarnoldtestapps.tk/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
我想我知道发生了什么事。
curl -vv -X POST https://www.lloydarnoldtestapps.tk
回应来自apacheServer: Apache/2.4.37
运行时,curl -vv -X POST http://www.lloydarnoldtestapps.tk:1337/webhook
响应来自快递X-Powered-By: Express
我认为当您首先开始表达并绑定到port 1337
apache时,它实际上无法绑定,所以这就是为什么您200
向port 1337
您不能从apache返回index.js。您将使用apache作为来自AWS(HTTPS)-> Apache(HTTP)-> Express的反向代理和代理请求。这样,Apache将终止https并通过http发出请求以表示。
查看Proxy和ProxyPass中的Apache和反向代理到Node.js服务器的教程。
查看此帖子ProxyPass apache https到节点服务器
特别是这些指令
ProxyPass / https://example.com:4433/
ProxyPassReverse / https://example.com:4433 /
如有任何疑问,请发回。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句