Nodejs cannot connect to server in ws: // apache proxy

I am trying to set up a nodejs app on localhost with a domain name.

So my site is in local language http://app.local

which points tohttp://localhost/app

Now I have a nodejs application running on port 6060 http://localhost:6060

I am trying to tune localhost:6060

tohttp://app.local/nodejs

Here is my apache config file.

 <VirtualHost app.local>
    ServerAdmin webmaster@app.local
    ServerName app.local
    ServerAlias app.local

    DocumentRoot /var/www/app

    ProxyPass /service http://localhost:3000
    ProxyPassReverse /service/ http://localhost:3000/

    ProxyPass /nodejs http://localhost:6060
    ProxyPassReverse /nodejs/ http://localhost:6060/

    ProxyPass /nodejs ws://localhost:6060
    ProxyPassReverse /nodejs/ ws://localhost:6060/

    <Directory >
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /var/www/app>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        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

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>


</VirtualHost>

      

My javascript code is listening:

var socket = io.connect('http://app.local/', {path:'/nodejs/socket.io/', port: 6060});
socket.on('connect', function(){
    console.log("Connected");
});

      

When I try to run my application through this URL http://app.local/nodejs

, it throws the following error:

Firefox can't establish a connection to the server at ws://app.local/nodejs/socket.io/?EIO=3&transport=websocket&sid=NQ2LSn--THwZkrStAAAH.

I followed this question but still didn't work.

I am using Apache / 2.4.7 (Ubuntu)

+3


source to share


1 answer


Try the following:

Edit

var socket = io.connect('http://app.local/', {path:'/nodejs/socket.io/', port: 6060});

      



to

var socket = io.connect('http://app.local:6060');

      

+1


source







All Articles