将Nginx配置为Couchdb的反向代理

时间:2016-04-01 17:21:14

标签: apache nginx docker couchdb reverse-proxy

我有一个无法直接访问的Couchdb数据库,所以我需要一个反向代理。 如何将Nginx或apache配置为Couchdb的反向代理?

2 个答案:

答案 0 :(得分:2)

要在nginx中反转代理,您需要一个类似于https://www.nginx.com/resources/admin-guide/reverse-proxy/

的配置
upstream  mycouch {
    server 192.168.0.100:
}

server {
    listen       *:80;
    server_name  mycouch.mydomain.whatever.com;
    underscores_in_headers on;

    location / {
     expires off;
     proxy_pass  http://mycouch;
     proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
     proxy_redirect off;
     proxy_buffering off;
     proxy_set_header        Host            $host;
     proxy_set_header        X-Real-IP       $remote_addr;
     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
   }
}

这将为您的couchdb代理HTTP调用。既然你用docker标记了这个问题,如果你想用这个东西烧一个容器,我建议你从nginx开始,https://hub.docker.com/_/nginx/(或者,只是按照原样将配置文件挂载到nginx映像)

答案 1 :(得分:1)

我使用了这个配置,它适用于我



...
location / {
    proxy_pass http://192.168.99.100:5984 //couchdb address
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    
    location ~ ^/(.*)/_changes {
    proxy_pass http://192.168.99.100:5984 //couchdb address
    proxy_redirect off;
    proxy_buffering off;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
...