我一直试图在NodeJS上设置SSL,使用index.html证书通过Apache2服务器为CertBot提供服务。
不幸的是,当我试图让客户机通过https连接到服务器时,它会引发以下错误
[index.js:83 GET https://pxlloewe.de:3000/socket.io/?EIO=3&transport=polling&t=NJ9t2YZ net::ERR_SSL_PROTOCOL_ERROR][1]

那么,是否仍然可以通过appache2和ssl提供文件并通过加载https:youDomain.com的页面连接到服务器?
我试图在NodeJS服务器上运行https,但我不想通过Express提供浏览器文件
这是我的代码,如果有人有机会读出来的话:
服务器端:
var express = require("express");
var socket = require("socket.io");
var app = express();
const port = 3000
var server = app.listen(port, () => {
console.log("Express App auf Port: ", port)
});
//Socket Setup
var io = socket(server);
io.on("connection", function(){
console.log("Verbunden auf websocket")
})客户端:
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js" integrity="sha512-v8ng/uGxkge3d1IJuEo6dJP8JViyvms0cly9pnbfRxT6/31c3dRWxIiwGnMSWwZjHKOuY3EVmijs7k1jz/9bLA==" crossorigin="anonymous"></script>
<title>Einfache Chat App</title>
<script src="chat.js"></script>
</html>联署材料:
// Make Connection
var socket = io.connect('pxlloewe.de:3000', {secure: true});发布于 2020-10-02 17:10:21
下面是我要让事情成功的步骤:
ServerName websocket.pxlloewe.de ServerAdmin Ich@bin.Gut DocumentRoot /var/www/html/pxlloewe_de ProxyPreserveHost On ProxyRequests On /socket.io http://localhost:3000/socket.io ProxyPassReverse /socket.io http://localhost:3000/socket.io #ProxyPass /socket.io http://localhost/ / ProxyPass /socket.io http://localhost/包括/etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile /etc/letsencrypt/live/pxlloewe.de-0001/fullchain.pem SSLCertificateKeyFile SSLCertificateKeyFile
谢谢你的帮助,阿维夫罗!现在做得很好。
发布于 2020-09-27 22:13:10
我要抓住这个阿帕奇网站。直接从我的生产现场。然后对其进行修改以满足您的需要。
<VirtualHost *:443>
ServerName pxlloewe.de
#ServerAlias www.pxlloewe.de
ServerAdmin admin@pxlloewe.de
DocumentRoot /var/www/pxlloewe_de
LogLevel debug ssl:info
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/pxlloewe.de.crt
SSLCertificateKeyFile /etc/apache2/ssl/pxlloewe.de.key
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule /(.*) ws://127.0.0.1:3000/$1 [P,L]
ProxyPass "/socket.io" "http://127.0.0.1:3000/socket.io"
ProxyPassReverse "/socket.io" "http://127.0.0.1:3000/socket.io"
ErrorLog ${APACHE_LOG_DIR}/knct_error_https.log
CustomLog ${APACHE_LOG_DIR}/knct_access_https.log combined
</VirtualHost>https://stackoverflow.com/questions/64076400
复制相似问题