最近因为工作的关系开发一个基于xmpp 协议的WEBIM项目,服务器用ejabberd ,IM服务器的版本为2.1.10,两个服务器在不同的domain,碰到垮域访问的问题,需在ejabberd 配置安全策略文件。具体解决方法:
1, 当应用程序的部署和ejabberd的部署不在一个domain 的时候,由于使用strophe.js 的插件flxhl.js 来与xmpp 服务器通讯。就会出现跨域问题,解决方法就是在ejabberd 服务器端放置crossdomain.xml 策略文件。
如:http://192.168.0.101:5280/crossdomain.xml可以访问到策略文件就说明正确配置了,具体配置如下:
A、 修改ejabberd.cfg文件
将
{mod_http_fileserver, [
{docroot, "D:\\Program Files\\ejabberd-2.1.10\\www"},
{accesslog, "D:\\Program Files\\ejabberd-2.1.10\\www/webaccess.log"},
{content_types, [{".htm", "text/html"}, {".xml", "text/xml"}]},
{directory_indices, ["crossdomain.xml", "index.html", "index.htm"]}
]}
这段配置前面的注释%%去掉,并在content_types后面增加{".xml", "text/xml"},注意使用逗号分隔;在 directory_indices 后面增加 crossdomain.xml索引文件。
将
{5280, ejabberd_http, [
%%{request_handlers, [
%% {["web"], mod_http_fileserver}
%%]},
captcha,
http_bind,
http_poll,
web_admin
]}
这段代码的注释%%去掉,{["web"], mod_http_fileserver} 修改为 {["crossdomain.xml"], mod_http_fileserver}。
保存所做的修改,重新启动服务器,就可以访问到crossdomain.xml文件了。
这里将mod_http_fileserver目录和索引文件设置为同名,在访问时直接输入目录名crossdomain.xml就可以访问到crossdomain.xml文件了。
crossdomain.xml文件的内容如下:
<?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <site-control permitted-cross-domain-policies="all"/> <allow-access-from domain="*" to-ports="*" secure="true"/> <allow-http-request-headers-from domain="*" headers="*" secure="true"/> </cross-domain-policy>