gpt4 book ai didi

node.js - Socket.io + NodeJS + Nginx + SSL

转载 作者:太空宇宙 更新时间:2023-11-03 13:26:03 26 4
gpt4 key购买 nike

当我使用 Nginx 时,我的套接字没有连接。我的配置文件是:

server {
listen 80;
return 301 https://$host$request_uri;
}

server {
listen 443;
server_name mysite.com

ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;

ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_prefer_server_ciphers on;
ssl_ciphers 'kEECDH+ECDSA+AES128 kEECDH+ECDSA+AES256 kEECDH+AES128 kEECDH+AES256 kEDH+AES128 kEDH+AES256 DES-CBC3-SHA +SHA !aNULL !eNULL !LOW !MD5 !EXP !DSS !PSK !SRP !kECDH !CAMELLIA !RC4 !SEED';

ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

keepalive_timeout 70;

access_log /var/log/nginx/dash.log;

# pass the request to the node.js server
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
add_header Front-End-Https on;

proxy_pass https://127.0.0.1:8081;
proxy_redirect off;

}
}

我的 NodeJS 是:

// Setup servers
var app = express();
var HTTPSOptions = {
cert: fs.readFileSync(config.ssl.server_cert),
key: fs.readFileSync(config.ssl.server_key),
requestCert: false,
rejectUnauthorized: false,
passphrase: config.ssl.server_password
};
HTTPSOptions.agent = new https.Agent(HTTPSOptions);

io = io.listen(server, {
log: false
});

io.sockets.on('connection', function (sock) {
console.log("CONNECTED");
});

var httpsServer = https.createServer(HTTPSOptions, app);

我的客户是

var socket = io.connect('https://localhost',  {secure: true});
socket.on('connect', function () {
console.log("CONNECTED HERE TOO");
});

不用说,两个 console.log 都没有显示任何内容。我担心 nginx 正在阻止请求而 Node 实际上从未收到请求?

最佳答案

好像少了listen 443 <b>ssl</b>;

关于node.js - Socket.io + NodeJS + Nginx + SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30317831/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com