【问题标题】:apache and nodejs proxyapache 和 nodejs 代理
【发布时间】: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 错误:&lt;Location /&gt; 应该是 &lt;Location&gt;。这可能是你问题的根源..

标签: node.js apache proxy


【解决方案1】:

/mysite/index.php

您要求 NodeJS 提供 PHP 页面。它不会那样做。

【讨论】:

  • 在这种情况下,我希望 node 以纯文本形式提供 PHP 页面 - 但它不应该导致错误。当 PHP 没有与 Apache 一起安装时也会发生同样的情况 - 它会提供源代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多