小编Her*_*nge的帖子

Akward 延迟将 Apache 的代理请求连接到 node.js 应用程序

在我的 Ubuntu Server 10.04 中,我正在运行一个示例 node.js 应用程序:

var http = require("http");

function onRequest(request, response) {

        console.log("Request received.");
        response.writeHead(200, {"Content-Type": "text/html"});
        response.write("Hello World");
        response.end();

}

http.createServer(onRequest).listen(3000);
Run Code Online (Sandbox Code Playgroud)

它只是侦听端口 3000 上的请求,登录控制台此请求并向客户端发送 HTTP “Hello World”

目标是使这个应用程序与 Apache2 共存。因此,经过一番研究后,我以这种方式编辑了默认文件(/etc/apache2/sites-available/default):

<VirtualHost *:80>
        ServerAdmin haj@myserver.com
        ServerName dev.myserver.com

        <Location /node>

                ProxyPassReverse http://127.0.0.1:3000/
                ProxyPass http://127.0.0.1:3000/

        </Location>

        <Proxy>
                Allow from all
        </Proxy>

        DocumentRoot /home/haj/www/http_home

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>

        <Directory /home/haj/www/http_home/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog /home/haj/www/log/error.log

        # …
Run Code Online (Sandbox Code Playgroud)

proxy node.js apache-2.2

12
推荐指数
1
解决办法
2万
查看次数

标签 统计

apache-2.2 ×1

node.js ×1

proxy ×1