Open lqdflying opened 3 years ago
可以在浏览器里按 F12
,然后切换到 网络/network
标签, 再点击同步,就可以看到具体报什么错误了。
一般客户端可以用,网页端出错的,基本就是跨域访问的问题。
如果你是直接访问 couchdb 端口的话,需要自己在 couchdb 配置文件上修改,可以参考官方文档。或者自己到 couchdb 后台服务器 http://xxx.xxx.xxx.xxx:5984/_utils
进行修改设置
[httpd]
enable_cors = true
[cors]
origins = *
如果你是通过 apache 或者 nginx 等 http 服务器反向代理的话,可能这些 http 服务器需要另外单独配置 cors.
配置确认已经修改,以下是F12的报错:
找到问题了,把https://markdown.xiaoshujiang.com/
换成http://markdown.xiaoshujiang.com/
就好了,两个协议浏览器不让互访,除非conchdb前边配置nginx+https也行,这样vps就必须要在国外,不能在国内了,因为得备案
再次补充,我配置了Apache2
的https
反向代理,同时开启了cors
,结果再次报错,我F12打开console
提示
The 'Access-Control-Allow-Origin' header contains multiple values'*', but only one is allowed
终于发现我过量配置了,解决办法:
注意: 如果用
Apache2
或者Nginx
做reverse proxy
,这里正常配置即可,不需要二次开启cors
因为conchdb
中的[httpd]
已经开启了一次了,这里不需要重复开启 前置Apache2
和conchdb
中的cors
保留一个即可
我把标题改成了wiki
,来帮助有需要的人
po一组测试过的配置: couchdb+apache2, debian10
[cors]
credentials = true
origins = *
headers = accept, authorization, content-type, origin, referer
methods = GET, PUT, POST, HEAD, DELETE
[httpd] enable_cors = true
- apache2.vh.config
```config
<IfModule mod_ssl.c>
<VirtualHost *:80>
ServerName couchdb.your_domain
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?(.*)$ https://%{SERVER_NAME}/$1 [L,R]
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/html
ServerName couchdb.your_domain
SSLEngine on
SSLCertificateFile /etc/apache2/cert/your_cert.crt
SSLCertificateKeyFile /etc/apache2/cert/your_cert.key
Header add Access-Control-Allow-Headers "accept, authorization, content-type, origin, referer"
Header add Access-Control-Allow-Methods "GET, PUT, POST, HEAD, DELETE"
ProxyPreserveHost On
ProxyPass / http://localhost:5984/
ProxyPassReverse / http://localhost:5984/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
</IfModule>
感谢分享 :+1:
WEB端自定义couchdb同时失败,本地PC客户端同步正常