You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在网站配置JavaScript XMPP Client(JSXC)?解决BOSH服务器404错误

Fixing "BOSH server NOT reachable or misconfigured" (404 Error) with JSXC + ejabberd

Hey there! I’ve run into this exact issue a few times when setting up JSXC with ejabberd—let’s walk through the fixes step by step to get your chat feature working.

1. First: Verify ejabberd’s BOSH Module is Enabled & Configured

The most common culprit is that ejabberd isn’t set up to serve the BOSH endpoint at /http-bind/. Here’s how to check and fix it:

  • Open your ejabberd configuration file (usually located at /etc/ejabberd/ejabberd.yml or ~/.ejabberd/ejabberd.yml).
  • Ensure the mod_bosh module is enabled in the modules section:
    modules:
      mod_bosh: {} # This line must exist—no extra config needed here for basic setup
    
  • Next, confirm the HTTP listener is configured to handle the /http-bind/ path. Look for the listen section and add/update this block:
    listen:
      - port: 5280 # Default ejabberd HTTP port
        module: ejabberd_http
        request_handlers:
          "/http-bind": mod_bosh # Maps the path to the BOSH module
          # You can add "/websocket": ejabberd_http_ws here too if you want WebSocket support later
    
  • Save the config and restart ejabberd to apply changes:
    # If using systemd
    sudo systemctl restart ejabberd
    
    # Or using ejabberdctl directly
    ejabberdctl restart
    

2. Test if the BOSH Endpoint is Actually Reachable

Before blaming JSXC, let’s confirm the /http-bind/ endpoint responds correctly. Run this curl command from your local machine or server:

curl -v http://example.com/http-bind/
  • If you get a 200 OK response with some XML content (like <body xmlns='http://jabber.org/protocol/httpbind'/>), the endpoint is working.
  • If you still get a 404, double-check your ejabberd config and restart again. If you’re using a reverse proxy (like Nginx) to route traffic to ejabberd, skip to the next section.

Reverse Proxy (Nginx) Check

If you’re using Nginx to serve your web app and proxy ejabberd traffic, make sure your Nginx config includes a location block for /http-bind/:

server {
    # Your existing web app config here...

    location /http-bind/ {
        proxy_pass http://localhost:5280/http-bind/; # Point to ejabberd's HTTP port
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

After updating Nginx, restart it with sudo systemctl restart nginx and retest the endpoint.

3. Double-Check JSXC’s BOSH URL Configuration

Even if ejabberd is set up correctly, JSXC will fail if the boshURL doesn’t match exactly. Here’s what your JSXC init code should look like:

jsxc.init({
    loginForm: {
        form: '#login-form',
        jid: '#jid-input',
        pass: '#password-input'
    },
    boshURL: 'http://example.com/http-bind/', // Must match the exact endpoint URL
    rosterAppend: '#jsxc-roster-container',
    loadSettings: true
});
  • Make sure there are no typos (like missing a trailing slash, or using https when your server uses http).
  • If your web app uses HTTPS, your BOSH URL should also use https://—ensure ejabberd is configured for HTTPS (either directly or via Nginx proxy).

4. Fix Cross-Origin (CORS) Issues

If your web app is hosted on a different domain than ejabberd, browsers will block the BOSH request unless ejabberd allows CORS. Add this to your ejabberd HTTP listener config:

listen:
    - port: 5280
      module: ejabberd_http
      request_handlers:
        "/http-bind": mod_bosh
      cors: true
      cors_allowed_origins: ["https://your-web-app-domain.com"] # Replace with your actual web app domain

Restart ejabberd after updating this.

5. Check Logs for Hidden Issues

If you’re still stuck, check ejabberd’s logs for clues:

# View live logs
ejabberdctl live

# Or check the log file directly
cat /var/log/ejabberd/ejabberd.log

Look for errors related to mod_bosh or HTTP requests—this can reveal issues like permission problems or misconfigured listeners.


内容的提问来源于stack exchange,提问作者Anil Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:58:56