I am trying to configure my nodejs application to run on localhost with a domain name.
我正在尝试将我的nodejs应用程序配置为在具有域名的localhost上运行。
So my website on local is http://app.local
which points to http://localhost/app
所以我在本地的网站是http://app.local,它指向http:// localhost / app
Now I have an app on nodejs which runs on 6060 port http://localhost:6060
现在我在nodejs上有一个应用程序,它运行在6060端口http:// localhost:6060上
I am trying to configure localhost:6060
to work on http://app.local/nodejs
我正在尝试配置localhost:6060以在http://app.local/nodejs上工作
Here's my apache config file.
这是我的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>
My javascript code listen emits:
我的javascript代码听发出:
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 the app through this URL http://app.local/nodejs
, it throws following error:
当我尝试通过此URL 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.
Firefox无法在ws://app.local/nodejs/socket.io/上建立与服务器的连接?EIO = 3&transport = websocket&sid = NQ2LSn - THwZkrStAAAH。
I followed this question but still not working.
我按照这个问题但仍然没有工作。
I am using Apache/2.4.7 (Ubuntu)
我正在使用Apache / 2.4.7(Ubuntu)
1 个解决方案
#1
Try the following:
请尝试以下方法:
Change
var socket = io.connect('http://app.local/', {path:'/nodejs/socket.io/', port: 6060});
to
var socket = io.connect('http://app.local:6060');
#1
Try the following:
请尝试以下方法:
Change
var socket = io.connect('http://app.local/', {path:'/nodejs/socket.io/', port: 6060});
to
var socket = io.connect('http://app.local:6060');