nginx反向代理到mongodb rest接口

4 nginx reverse-proxy mongodb

我正在尝试使用代理 MongoDB 的 REST 接口的 HTTP 身份验证设置反向代理。到目前为止,我有这个:

server {
        listen 80;
        server_name tld.example.com;
        charset utf-8;
        access_log /home/jill/logs/nginx.access.log main;

        # Redirect all HTTP traffic to HTTPS URL
        rewrite ^(.*) https://tld.example.com$1 permanent;
}

server {
        listen 443;
        server_name tld.example.com;

        ssl on;
        ssl_prefer_server_ciphers on;
        ssl_protocols           TLSv1 SSLv3;
        ssl_ciphers             HIGH:!ADH:!MD5:@STRENGTH;
        ssl_session_cache       shared:TLSSL:16m;
        ssl_session_timeout     10m;
        ssl_certificate /path/to/cert/tld.example.com.bundle.crt;
        ssl_certificate_key /path/to/cert/tld.example.com.key;

        gzip on;
        gzip_vary on;
        gzip_comp_level 6;

        keepalive_timeout 300;
        keepalive_requests 500;

        location / {
                proxy_pass https://127.0.0.1:28017;

                proxy_redirect     off;

                proxy_max_temp_file_size 0;

                proxy_connect_timeout      90;
                proxy_send_timeout         90;
                proxy_read_timeout         90;

                proxy_buffer_size          4k;
                proxy_buffers              4 32k;
                proxy_busy_buffers_size    64k;
                proxy_temp_file_write_size 64k;

                add_header Cache-Control no-cache;

        }

        auth_basic "Restricted area";
        auth_basic_user_file /path/to/password/file;
}
Run Code Online (Sandbox Code Playgroud)

这不起作用(显然),并导致网关超时。否则,我可以使用curl localhost:28017类似的方式从服务器内本地访问 REST 接口。

我究竟做错了什么?

pkh*_*mre 6

鉴于curl localhost:28017有效,我假设 REST 接口使用 HTTP 而不是 HTTPS。

更改以下行

proxy_pass https://127.0.0.1:28017;
Run Code Online (Sandbox Code Playgroud)

有了这个

proxy_pass http://127.0.0.1:28017;
Run Code Online (Sandbox Code Playgroud)