【问题标题】:neo4j webinterface behind nginx reverse proxynginx反向代理后面的neo4j web界面
【发布时间】:2014-07-22 15:37:22
【问题描述】:

我正在尝试向互联网公开 neo4j 数据库。

出于安全原因,我想通过 nginx 将其隐藏在 SSL/basic_auth 组合后面。下面是对应的nginx配置:

  location /neo4j/ {
            proxy_pass https://localhost:7473/;
            proxy_read_timeout 600;

            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 https;
            proxy_set_header    Host              $http_host;
            proxy_buffering     off;
            proxy_redirect      off;
            auth_basic           "restricted";
            auth_basic_user_file /etc/nginx/auth/htpasswd;
            proxy_headers_hash_max_size 1024;
            proxy_headers_hash_bucket_size 128;
            proxy_ssl_session_reuse off;
            rewrite /neo4j/(.*) /$1 break;
    }

虽然我可以访问 https://example.com/neo4j/browser,但网络界面告诉我,它无法连接到 neo4j,并且我的网络浏览器控制台被 OPTIONS https://example.com/db/data 405(Not allowed) 填满

我还尝试了结合身份验证扩展 (https://github.com/neo4j-contrib/authentication-extension) 的 https 服务器内置 neo4j。 使用此选项,我还可以访问 Web 界面。

但界面也显示,它无法连接到 neo4j 并且 webbrowser 的控制台被 OPTIONS http://example.com:7473/db/data/ net::ERR_EMPTY_RESPONSE 和提示 The page at 'https://example.com:7473/browser/' was loaded over HTTPS, but displayed insecure content from 'http://example.com:7473/db/data/': this content should also be loaded over HTTPS. 填满

有谁知道,如何让它工作?非常感谢!

【问题讨论】:

标签: ssl nginx proxy neo4j reverse-proxy


【解决方案1】:

我遇到了同样的问题,但缺乏关于 Nginx 作为网络服务器与 neo4j 结合的信息有点奇怪。奇怪的是,官方文档中唯一提到反向代理的是 Apache - 没有留下深刻印象。

仅供参考,我使用的是 dockerised neo4j (https://github.com/neo4j/docker-neo4j/tree/master/2.3.2),因为它默认提供(以防您想知道其他设置)。如果您在 docker 之外本地运行 neo4j,则无关紧要。下面的 Nginx conf 将是相同的。

location /neo4j/ {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_buffering off;
            proxy_pass http://YOUR-IP:7474/browser/;
 }

 location /db/data/ {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                proxy_buffering off;
                proxy_pass http://YOUR-IP:7474/db/data/;
}

如果您使用的是 HTTPS 而不是 HTTP,请将 YOUR-IP 替换为您的,并将 7474 更改为 7473

这对我有用。

【讨论】:

    【解决方案2】:

    需要OPTIONS 请求来验证与 Neo4j 服务器的连接。我认为它是验证连接的心跳。好像 Nginx 不支持OPTIONS 请求,但是可以这样截取请求:

    location / {
        if ($request_method = OPTIONS ) {
            add_header Access-Control-Allow-Origin "https://example.com";
            add_header Access-Control-Allow-Methods "GET, OPTIONS";
            add_header Access-Control-Allow-Headers "Authorization";
            add_header Access-Control-Allow-Credentials "true";
            add_header Content-Length 0;
            add_header Content-Type text/plain;
            return 200;
        }
    }
    

    来源:http://blog.rogeriopvl.com/archives/nginx-and-the-http-options-method/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-01
      • 2020-09-05
      • 1970-01-01
      • 2010-12-03
      相关资源
      最近更新 更多