用openfire+strophe搭建WEB IM平臺 - nomousewch的專欄 - 博客頻道 - CSDN.NETphp
- 準備
- openfire服務器(http://www.igniterealtime.org)——IM Server
- ngnix服務器(http://nginx.org)——代理和HTTP Server
- strophe庫(http://strophe.im/)——JS客戶端
- 安裝和配置openfire
openfire的安裝見本人博客,安裝時配置domain爲172.17.125.161(注意除非PC配置了域名,否則最好domain配置爲IP,方便客戶端訪問),後登陸管理控制檯,服務器》服務器設置》HTTP綁定,默認啓用7070端口做爲HTTP綁定端口。html
- 安裝和配置nginx
我安裝的是windows版,直接解壓到本地目錄,打開conf目錄下nginx.conf,修改server節點爲以下:nginx
- server {
- listen 80;
- server_name 172.17.125.161;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- location / {
- root html;
- index index.html index.htm;
- }
- location /http-bind {
- proxy_pass http://172.17.125.161:7070/http-bind/;
- proxy_redirect off;
- proxy_read_timeout 120;
- proxy_connect_timeout 120;
- }
- #error_page 404 /404.html;
- # redirect server error pages to the static page /50x.html
- #
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- # proxy the PHP scripts to Apache listening on 127.0.0.1:80
- #
- #location ~ \.php$Snbsp;{
- # proxy_pass http://127.0.0.1;
- #}
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- #
- #location ~ \.php$Snbsp;{
- # root html;
- # fastcgi_pass 127.0.0.1:9000;
- # fastcgi_index index.php;
- # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
- # include fastcgi_params;
- #}
- # deny access to .htaccess files, if Apache's document root
- # concurs with nginx's one
- #
- #location ~ /\.ht {
- # deny all;
- #}
- }
server { listen 80; server_name 172.17.125.161; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } location /http-bind { proxy_pass http://172.17.125.161:7070/http-bind/; proxy_redirect off; proxy_read_timeout 120; proxy_connect_timeout 120; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }而後雙擊nginx.exe,在任務管理器下看到兩個nginx.exe進程說明啓動成功。windows
- 安裝strophe
下載strophejs-1.0.2.zip包,直接解壓至nginx目錄下的html文件夾內。瀏覽器
- 測試鏈接
進入strophejs-1.0.2解壓目錄,打開examples/basic.js,修改服務器
- var BOSH_SERVICE = 'http://im/http-bind/'
var BOSH_SERVICE = 'http://im/http-bind/'爲:session
- var BOSH_SERVICE = 'http://172.17.125.161/http-bind/'
var BOSH_SERVICE = 'http://172.17.125.161/http-bind/'
打開瀏覽器,訪問 http://172.17.125.161/strophejs-1.0.2/examples/basic.html,輸入完整的JID(例如:nomouse@172.17.125.161)和密碼,點擊connect,出現下列輸入說明登陸成功:app
- SENT: <body rid='4218693533' xmlns='http://jabber.org/protocol/httpbind' to='172.17.125.161' xml:lang='en' wait='10' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>
- RECV: <body xmlns='http://jabber.org/protocol/httpbind' xmlns:stream='http://etherx.jabber.org/streams' authid='74ec6e82' sid='74ec6e82' secure='true' requests='2' inactivity='30' polling='0' wait='10' hold='1' ack='4218693533' maxpause='300' ver='1.6'><stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns='http://jabber.org/features/compress'><method>zlib</method></compression><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></stream:features></body>
- SENT: <body rid='4218693534' xmlns='http://jabber.org/protocol/httpbind' sid='74ec6e82'><auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/></body>
- SENT: <body rid='4218693534' xmlns='http://jabber.org/protocol/httpbind' sid='74ec6e82'><auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/></body>
- SENT: <body rid='4218693534' xmlns='http://jabber.org/protocol/httpbind' sid='74ec6e82'><auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/></body>
SENT: <body rid='4218693533' xmlns='http://jabber.org/protocol/httpbind' to='172.17.125.161' xml:lang='en' wait='10' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/> RECV: <body xmlns='http://jabber.org/protocol/httpbind' xmlns:stream='http://etherx.jabber.org/streams' authid='74ec6e82' sid='74ec6e82' secure='true' requests='2' inactivity='30' polling='0' wait='10' hold='1' ack='4218693533' maxpause='300' ver='1.6'><stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns='http://jabber.org/features/compress'><method>zlib</method></compression><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></stream:features></body> SENT: <body rid='4218693534' xmlns='http://jabber.org/protocol/httpbind' sid='74ec6e82'><auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/></body> SENT: <body rid='4218693534' xmlns='http://jabber.org/protocol/httpbind' sid='74ec6e82'><auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/></body> SENT: <body rid='4218693534' xmlns='http://jabber.org/protocol/httpbind' sid='74ec6e82'><auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/></body>