2015-05-04 59 views
3

我試圖將我的nodejs應用程序配置爲在具有域名的本地主機上運行。Nodejs無法在ws:// apache代理上建立與服務器的連接

所以,我對當地的網站是http://app.local指向http://localhost/app

現在我對的NodeJS應用程序運行於6060端口http://localhost:6060

我想配置localhost:6060http://app.local/nodejs

工作這是我的apache配置文件。

<VirtualHost app.local> 
    ServerAdmin [email protected] 
    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"); 
}); 

當我試圖通過這個網址http://app.local/nodejs運行應用程序,它拋出以下錯誤:

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

我跟着這個question但仍然無法正常工作。

我使用的Apache/2.4.7(Ubuntu的)

回答

1

嘗試以下操作:

變化

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

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

爲什麼將這項工作?看起來和他以前一樣。 – kabuto178

相關問題