While experimenting with node.js on my vps I stumbled across a problem I can not seem to get fixed.
I have an apache server running alongside node.js on ubuntu 13.04. My idea was to create a reverse proxy using node-http-proxy. Enough information about this can be found, but I seem to have an error that I can not find.
First I changed the apache ports:
NameVirtualHost *:9000
Listen 9000
Then I have my hello.js file:
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!");
and finally the apache somesite.com config:
<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>
I have a basic html file in public_html to make sure everything is working. When I start both servers and go to somesite.com then I just see a blank wepbage (if I inspect source there is nothing, instead of my own file).
If I start a simple node server on another port and route traffic to that port, that works, so I'm assuming my problem is apache related, but I can't figure out what is wrong.
Edit 1: Apparently my proxy only worked for somesite.com and not www.somesite.com. If I go to somesite.com I get:
An error has occurred: {"code":"EINVAL","errno":"EINVAL","syscall":"connect"}
Edit 2: If I check the access and error log from apache it seems it never receives anything. No messages of me to be found
Edit 3: I changed the port on which nodejs is listening, thinking that maybe the running as root has something to do with it, but even running on a random high port, it is not working. It can't seem to make a connection between itself and the apache socket (which works perfectly when I directly browse to it).
Apparently replacing 127.0.0.1 with localhost in the hello.js script did the trick. Not completely sure why (I guess it has something to do with my hosts file), but it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.