I dont have much experience neither in Node.js not in socket.io, thus maybe I will ask silly questions and sorry for that first of all.
I am trying to do following:
Created virtual host in apache and set it as proxy to node. My conf file looks like:
<VirtualHost *:80>
ServerAdmin giorgi@omedia.ge
ServerName node.aidemo.info
ServerAlias www.node.aidemo.info
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://127.0.0.1:8080
ProxyPassReverse http://127.0.0.1:8080
</Location>
</VirtualHost>
Have created simple js file for server (first server example in socket.io website) and started server from cli with command: node server.js. It starts perfectly and listens to 8080
Created another virtualhost where I put clientside index.html (also from first example in socket.io). At first I had problem (and actually main problem is this), browser couldn't resolve path /socket.io/socket.io.js. Then I went to the url (http://localhost:8080/socket.io/socket.io.js) from lynx locally from terminal, downloaded that js and put locally with virtualhost near index.html. After this, browser could resolve that request, but I have error when socket.io.js itself is trying to get the url:
http://localhost:8080/socket.io/1/?t=1347623348836
Do you have any ideas how can I solve this problem? My main goal is to have web url from which I can access my node server and talk with it with socket.io - for example to create very simple chat.
I hope I was clear. Thank you everyone who will try to help.
I am using express + socket.io and they are listening on port 3001
. And I want http://example.com/folder
to redirect to my Express app listening on port 3001
(i.e, to http://localhost:3001
, server-side).
I have done the following.
The .html file has this:
<script src='/folder/socket.io/socket.io.js'> </script>
<script>
var socket = io.connect('http://example.com', {resource: 'folder/socket.io'});
...
</script>
And my apache2 conf looks like this:
ProxyPreserveHost On
ProxyPass /folder/ http://localhost:3001/
ProxyPassReverse /folder/ http://localhost:3001/
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /folder/>
allow from all
</Location>
Note that it requires the module proxy_http
to be enabled. To enable it, run this command:
sudo a2enmod proxy_http; service apache2 restart
http://localhost:8080
is obviously not going to be available to anything outside of your server.
The client-side javascript's io.connect()
should be connecting to http://node.aidemo.info
so that apache can send that off to Node.
http://node.aidemo.info:8080
might also work if you've opened up port 8080.