我正在尝试使用代理MongoDB的REST接口的HTTPvalidation来设置反向代理。 到目前为止,我有这样的:
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; }
这不起作用(显然),并导致网关超时。 否则,我可以使用curl localhost:28017和类似的方法从服务器本地访问REST接口。
我究竟做错了什么?
考虑到curl localhost:28017作用,我认为REST接口说HTTP而不是HTTPS。
更改以下行
proxy_pass https://127.0.0.1:28017;
有了这个
proxy_pass http://127.0.0.1:28017;
为了提供MongoDB方面的替代解决scheme(如果您想要使用HTTPS端到端),您可以在MongoDB中启用SSL:
http://docs.mongodb.org/manual/administration/ssl/
你也可以在这里看到我以前的答案,关于在MongoDB中使用SSL的更多细节:
https://serverfault.com/a/376598/108132
启用SSL也可以在REST界面上启用它。 只是为了确保我在默认端口上使用启用了SSL的版本对其进行了testing:
curl -I -k https://127.0.0.1:28017 HTTP/1.0 200 OK Content-Type: text/html;charset=utf-8 Connection: close Content-Length: 21343
-k是必要的,因为我正在使用自签名证书进行testing。