【发布时间】:2014-01-10 19:04:07
【问题描述】:
我希望 nodejs 与 apache 一起工作。
我尝试编辑apache的httpd,像这样
<VirtualHost *:80>
ServerAdmin info@admin.bb
ServerName www.myserver.net
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:8000/
ProxyPassReverse http://localhost:8000/
</Location>
</VirtualHost>
我在许多博客和 SO 中都看到了上述方法。我保存了,我重新启动了 apache,我得到了
502 Proxy Error
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /mysite/index.php.
Reason: Error reading from remote server
这个方法有什么问题?
原谅我的无知,我不知道如何解决这个问题。
这里是节点服务器的部分,我在这里设置了一个服务器...
"use strict";
var WebSocketServer = require('websocket').server;
var http = require('http');
var pg = require('pg');
var server = http.createServer(function(request, response) {
console.log((new Date()) + ' Received request for ' + request.url);
response.writeHead(200, {'Content-Type': 'text/html'});
response.end(clientHtml);
});
server.listen(8000, function() {
console.log((new Date()) + ' Server is listening on port 8000');
});
var wsServer = new WebSocketServer({
httpServer: server,
autoAcceptConnections: false
});
function originIsAllowed(origin) {
return true;
}
//FALLBACKING FOR WEBSOCKETS
var pf = require('policyfile').createServer();
pf.listen( server, function(){
console.log(':3 yay')
});
//STOPS HERE
wsServer.on('request', function(request) {
if (!originIsAllowed(request.origin)) {
request.reject();
console.log((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');
return;
}
//////////////
//prepare things to distinguish connections
var connections = {};
var connectionIDCounter = 0;
var connection = request.accept(null, request.origin);
// Store a reference to the connection using an incrementing ID
connection.id = connectionIDCounter ++;
connections[connection.id] = connection;
console.log((new Date()) + ' Connection accepted.');
【问题讨论】:
-
您的 Apache 配置中有一个 XML 错误:
<Location />应该是<Location>。这可能是你问题的根源..