nginx反向代理背后的neo4j webinterface

udo*_*udo 7 ssl proxy reverse-proxy nginx neo4j

我正在尝试将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;
    }
Run Code Online (Sandbox Code Playgroud)

虽然我可以访问https://example.com/neo4j/browser,webinterface告诉我,它无法连接到neo4j,我的webbrowser的控制台被填满了OPTIONS https://example.com/db/data 405(Not allowed)

我还尝试了内置在https服务器中的neo4j以及身份验证扩展(https://github.com/neo4j-contrib/authentication-extension).使用此选项,我还可以访问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.

有谁知道,如何使它工作?提前谢谢了!

fel*_*ipe 7

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

仅供参考,我使用的是 dockerized neo4j ( https://github.com/neo4j/docker-neo4j/tree/master/2.3.2 ),因为它是默认的(如果你想知道其他设置)。如果您在 docker 之外本地运行 neo4j 应该没有关系。下面的 Nginxconf 也是一样的。

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/;
}
Run Code Online (Sandbox Code Playgroud)

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

这对我有用。


Wil*_*yon 3

需要该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;
    }
}
Run Code Online (Sandbox Code Playgroud)

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