在我的 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)