node.js - Nodejs 无法与位于 ws ://apache proxy 的服务器建立连接

标签 node.js apache2

我正在尝试将我的 nodejs 应用程序配置为在具有域名的本地主机上运行。

所以我在本地的网站是 http://app.local 指向 http://localhost/app

现在我在 nodejs 上有一个应用程序,它运行在 6060 端口 http://localhost:6060

我正在尝试配置 localhost:6060 以在 http://app.local/nodejs

上工作

这是我的 apache 配置文件。

 <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>

我的 javascript 代码监听发出:

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

当我尝试通过此 URL http://app.local/nodejs 运行应用程序时,它会抛出以下错误:

Firefox 无法与位于 ws://app.local/nodejs/socket.io/?EIO=3&transport=websocket&sid=NQ2LSn--THwZkrStAAAH 的服务器建立连接。

我关注了这个question但仍然无法正常工作。

我正在使用 Apache/2.4.7 (Ubuntu)

最佳答案

尝试以下操作:

改变

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

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

关于node.js - Nodejs 无法与位于 ws ://apache proxy 的服务器建立连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30026064/

相关文章:

node.js sequelize 关联,包括条件

javascript - 从 Node.js 中的 Json 对象下载文件

javascript - 使用 Socket.io 的异步模块加载 (AMD)

javascript - 没有这样的文件或目录 react-native/scripts/libraries

apache - 根据url和referrer删除cookie

php - Web 服务 API - 哪种语言更好?

python - wsgi 与 python3.4 和 python2.7

node.js - 是否可以将自动搜索字段从硬编码 'suggestions' 更改为数据库中的数据?

apache2 - Apache 2.4.6 的新站点配置文件

php - Heroku 1x 与 2x 网络测功机