[英]Reverse proxy from NodeJS to Apache using node-http-proxy does not work
在我的vps上試驗node.js時,我偶然發現了一個似乎無法解決的問題。
我在Ubuntu 13.04上有一個與node.js一起運行的apache服務器。 我的想法是使用node-http-proxy創建反向代理。 可以找到關於此的足夠的信息,但是我似乎有一個找不到的錯誤。
首先,我更改了apache端口:
NameVirtualHost *:9000
Listen 9000
然后我有我的hello.js文件:
var http = require('http');
var httpProxy = require('http-proxy');
var options = {
router: {
'somesite.com': '127:0:0:1:9000'
}
}
var proxyServer = httpProxy.createServer(options).listen(80);
console.log("Proxy server running!");
最后是apache somesite.com配置:
<VirtualHost *:9000>
ServerName somesite.com
ServerAdmin info@somesite.com
ServerAlias www.somesite.com
DocumentRoot /var/www/somesite.com/public_html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
我在public_html中有一個基本的html文件,以確保一切正常。 當我同時啟動兩個服務器並訪問somesite.com時,我只會看到空白的webbage(如果我檢查源代碼,則沒有任何東西,而不是我自己的文件)。
如果我在另一個端口上啟動一個簡單的節點服務器並將流量路由到該端口,則可以正常工作,因此我假設我的問題與apache相關,但我無法弄清楚出了什么問題。
編輯1:顯然我的代理服務器僅適用於somesite.com,而不適用於www.somesite.com。 如果我去somesite.com我會得到:
An error has occurred: {"code":"EINVAL","errno":"EINVAL","syscall":"connect"}
編輯2:如果我從apache檢查訪問和錯誤日志,似乎它什么也沒收到。 找不到我的消息
編輯3:我更改了nodejs監聽的端口,以為以root身份運行可能與此有關,但是即使在隨機高端口上運行,它也無法正常工作。 它似乎無法在自己和apache套接字之間建立連接(當我直接瀏覽到apache套接字時,它可以很好地工作)。
顯然在hello.js腳本中用localhost替換了127.0.0.1可以解決問題。 不能完全確定為什么(我想這與我的主機文件有關),但是可以。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.