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:
- Installed node on ubuntu where I have apache also installed.
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.
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 tohttp://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.I am using express + socket.io and they are listening on port
3001
. And I wanthttp://example.com/folder
to redirect to my Express app listening on port3001
(i.e, tohttp://localhost:3001
, server-side).I have done the following.
The .html file has this:
And my apache2 conf looks like this:
Note that it requires the module
proxy_http
to be enabled. To enable it, run this command:If you put
socket.io.js
file locally near yourindex.html
file, it will not resolve the problem because you probably didn't change the url in yoursocket
var inmain.js
file, look at:in your
main.js/index.html
(script)replace with:
My code source look like this: