反向代理 CouchDB Web 前端(Futon),无需公开 CouchDB API

反向代理 CouchDB Web 前端(Futon),无需公开 CouchDB API

是否有可能只是反向代理 Futon,无需公开 CouchDB 根和 RESTful API?我有以下 nginx 配置:

server {
  # This should never be hit, as the port isn't open,
  # but it's here for completeness sake
  listen 80;
  return 301 https://$host$request_uri;
}

server {
  listen 443;
  server_name my_futon_host;

  ssl_certificate /path/to/my/certificate.pem;
  ssl_certificate_key /path/to/my/private.key;

  ssl on;
  ssl_session_cache builtin:1000 shared:SSL:10m;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
  ssl_prefer_server_ciphers on;

  location / {
    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;

    # Just reverse proxy Futon, presuming that works...
    proxy_pass          http://localhost:5984/_utils/;
    proxy_read_timeout  90;

    proxy_redirect      http://localhost:5984/_utils/ https://my_futon_host/;
  }
}

Futon 似乎已使用此配置加载,但我什么也做不了。它只是抱怨无法访问适当的 CouchDB API 端点。这是有道理的,因为它们没有反向代理,并且 Futon 可能试图直接调用它们。有什么办法可以解决这个问题吗?

答案1

按照以下方式编写位置块对我来说是可行的。关键行是为路径添加重写指令。

location / { rewrite ^/(.*) /_utils/$1 break; proxy_pass http://localhost:5984; proxy_set_header Host $host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; }

相关内容