blog icon indicating copy to clipboard operation
blog copied to clipboard

走马观花之 CouchDB

Open Bpazy opened this issue 3 years ago • 1 comments

CouchDB 的安装等记录

Bpazy avatar Nov 21 '22 17:11 Bpazy

安装

直接 docker-compose 启动:

version: "3.7"
services:
    couchserver:
        image: couchdb:3.1.2
        ports:
            - "127.0.0.1:5984:5984"
        environment:
            - COUCHDB_USER=example
            - COUCHDB_PASSWORD=YOUR_PASSWORD
        volumes:
            - /home/ubuntu/couchdb/data/couchdb:/opt/couchdb/data
            - /home/ubuntu/couchdb/conf/local.ini:/opt/couchdb/etc/local.ini

/home/ubuntu/couchdb/conf/local.ini 指定了一些配置,以让它可以用于 Self-hosted LiveSync,如下:

[couchdb]
single_node = true
max_document_size = 50000000

[chttpd]
require_valid_user = true
max_http_request_size = 4294967296

[chttpd_auth]
require_valid_user = true
authentication_redirect = /_utils/session.html

[httpd]
WWW-Authenticate = Basic realm="couchdb"
enable_cors = true

[cors]
origins = app://obsidian.md,capacitor://localhost,http://localhost
credentials = true
headers = accept, authorization, content-type, origin, referer
methods = GET, PUT, POST, HEAD, DELETE
max_age = 3600

然后配置 nginx 转发请求

server {
    listen 443 ssl;
    server_name couchdb.example.host;

    ssl_certificate     /etc/nginx/ssl/fullchain.cer;
    ssl_certificate_key /etc/nginx/ssl/example.host.key;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;


    location / {
        proxy_pass http://localhost:5984;
        proxy_redirect off;
        proxy_buffering off;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Proxy buffering 必须关闭, 否则 continuous replication 无法正常工作。

你也可以不配置 SSL 证书,但是不配置的话移动端就无法使用,关于 SSL 证书的配置可以参考: #138

Bpazy avatar Nov 21 '22 17:11 Bpazy