You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何通过单端口(80)访问Neo4j Server 3.1.4?

Yes, you absolutely can access your Neo4j 3.1.4 instance through a single port 80 behind Nginx—this is totally doable by leveraging Nginx's ability to route regular HTTP traffic and WebSocket connections separately. The root of your WebSocket error is that the Neo4j Browser uses WebSocket to communicate with the Bolt protocol, so we just need to configure Nginx to forward those WebSocket requests to Neo4j's Bolt port while handling regular HTTP traffic for the Browser itself.

Step 1: Update Neo4j Configuration

First, tweak your neo4j.conf to ensure external connections are allowed and WebSocket support for Bolt is enabled:

  • Uncomment and set these lines correctly:
    dbms.connector.http.enabled=true
    dbms.connector.http.address=0.0.0.0:7474
    dbms.connector.bolt.enabled=true
    dbms.connector.bolt.address=0.0.0.0:7687
    dbms.websocket.enabled=true
    

This ensures Neo4j listens on all network interfaces for both HTTP and Bolt, and enables WebSocket access for the Bolt protocol.

Step 2: Configure Nginx to Route Traffic

Next, update your Nginx server block to listen on port 80, routing regular HTTP requests to Neo4j's 7474 port and WebSocket requests (for Bolt) to 7687. Here's a tested configuration:

server {
    listen 80;
    server_name your-server-ip-or-domain; # Replace with your actual IP/domain

    # Forward regular HTTP traffic to Neo4j's Browser endpoint
    location / {
        proxy_pass http://localhost:7474;
        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_set_header X-Forwarded-Proto $scheme;
    }

    # Handle Bolt WebSocket connections (critical for Browser-Bolt communication)
    location /db/data/bolt {
        proxy_pass http://localhost:7687;
        proxy_http_version 1.1;
        # These headers are mandatory for WebSocket protocol upgrade
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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_set_header X-Forwarded-Proto $scheme;
    }
}

Step 3: Adjust Neo4j Browser Connection Settings

After restarting both Nginx and Neo4j, access the Browser via http://your-server-ip-or-domain. When connecting to Bolt:

  • Instead of using bolt://localhost:7687, enter the WebSocket URL: ws://your-server-ip-or-domain/db/data/bolt
  • In most cases, the Browser will auto-detect this proxy-compatible URL if you're accessing it through the Nginx endpoint, but manual entry works if auto-detection fails.

Quick Troubleshooting Tips

  • Confirm your firewall allows Nginx to access local ports 7474 and 7687.
  • Verify Neo4j is running and listening on both ports with netstat -tulpn | grep neo4j.
  • Check Nginx's error logs (usually at /var/log/nginx/error.log) if you still see WebSocket errors—they often highlight connection issues between Nginx and Neo4j.

内容的提问来源于stack exchange,提问作者Aspiration Tao

火山引擎 最新活动