gpt4 book ai didi

node.js - Apache ProxyPass 和 Node.js - 不提供 socket.io

转载 作者:太空宇宙 更新时间:2023-11-04 02:21:01 24 4
gpt4 key购买 nike

我尝试在现有的 apache 旁边运行 Node.js,但在从 Express.js 服务器提供内容时遇到 ProxyPass 问题。问题似乎在于 Node 服务器在 Apache 转发时看到的请求。

我尝试了这个配置:

<VirtualHost *:80>
DocumentRoot "/var/www/html"
ProxyPreserveHost on
ProxyPass /node http://localhost:3000/
ProxyPassReverse /node http://localhost:3000/
</VirtualHost>

Node 设置服务器如下:

var express = require('express')
, app = express()
, server = require('http').createServer(app)
, io = require("socket.io").listen(server)

app.use(function(req, res, next){
console.log(req.method, req.url); // log the method and route
next();
});
app.use(express.static(__dirname + '/public'));
app.use('/components', express.static(__dirname + '/components'));
app.use('/js', express.static(__dirname + '/js'));

我得到了 Node 的记录:

GET /
GET //components/bootstrap/dist/css/bootstrap.css
GET //components/font-awesome/css/font-awesome.css
GET //css/flags.css
GET //css/app.css
GET //components/jquery/dist/jquery.js
GET //components/bootstrap/dist/js/bootstrap.js
GET //socket.io/socket.io.js
GET //js/client.js
GET //components/bootstrap/dist/css/bootstrap.css.map

问题:当 apache 发送请求并且不提供 socket.io 库时,我收到了额外的斜杠。如何让 Apache 在到达 Node.js 之前删除前导斜杠?

最佳答案

我最终选择使用 HAProxy 来取代 Node 和 apache;正如上面评论中所建议的。

这些是我使用的设置:

 frontend main
bind *:80
mode http
default_backend apache

acl is_node path_beg -i /node/
use_backend node if is_node

acl is_node_too path_beg -i /node
use_backend node if is_node_too

acl is_socket path_beg -i /socket.io/
use_backend socketio if is_socket

acl is_socketio_too path_beg -i /socket.io
use_backend socketio if is_socketio_too

backend apache
mode http
balance roundrobin
server apache localhost:81

backend node
mode http
balance roundrobin
server node localhost:3000
reqrep ^([^\ :]*)\ /node/(.*) \1\ /\2
reqrep ^([^\ :]*)\ /node(.*) \1\ /\2

backend socketio
mode http
balance roundrobin
server node localhost:3000
reqrep ^([^\ :]*)\ /node/(.*) \1\ /\2
reqrep ^([^\ :]*)\ /node(.*) \1\ /\2

关于node.js - Apache ProxyPass 和 Node.js - 不提供 socket.io,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33425499/

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