问题描述
请提供建议。我在前端和CouchDB上使用Vue进行授权和数据存储。我还将Nginx用作Web服务器。一切都很好,但是现在我需要使用另一个Nginx服务器进行负载平衡。也就是说,电路现在看起来像这样 Nginx(负载均衡器)-> Nginx(Web服务器)-> CouchDB
问题是,现在我不在最后一个服务器上获取Set-Cookie标头,如果我不使用它,则一切正常,授权正常。
请告诉我可能是什么问题?
这是我的配置:
CouchDB:
[httpd]
enable_cors = true
WWW-Authenticate = Other realm="app"
bind_address = 0.0.0.0
[chttpd]
bind_address = 0.0.0.0
authentication_handlers = {chttpd_auth,cookie_authentication_handler},{chttpd_auth,proxy_authentication_handler},default_authentication_handler}
proxy_use_secret = false
[couch_httpd_auth]
require_valid_user = false
timeout = 86400
cookie_domain = {load_balancer_domain_name}
same_site = strict
[cors]
origins = http://load_balancer_domain_name,http://load_balancer_domain_ip //just in case
credentials = true
[couch_httpd_oauth]
use_users_db = true
upstream upstream_name {
server Nginx_WEB_SERVER_IP;
}
server {
listen 80 default_server;
# proxy_next_upstream error;
root /var/www/html;
index index.html index.htm index.PHP;
set_real_ip_from Nginx_LOAD_BALANCER_IP;
real_ip_header X-Real-IP;
location / {
proxy_pass http://upstream_name/;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
#add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
proxy_redirect off;
proxy_set_header host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-forward-for $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
proxy_cookie_domain host $host;
}
}
和Nginx Web服务器:
upstream couchdb {
server couchdb:5984;
}
server {
listen 80 default_server;
server_name localhost;
root /var/www/html;
index index.html index.htm index.PHP;
location / {
add_header 'Referrer-Policy' 'origin';
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'false';
add_header 'Access-Control-Allow-Headers' 'Authorization,Range';
add_header 'Access-Control-Allow-Methods' 'GET,PATCH';
try_files $uri $uri/ =404;
error_page 404 = /index.PHP;
}
# Pass couchdb requests to the right root.
location /couchdb/ {
add_header 'Referrer-Policy' 'origin';
add_header 'Access-Control-Allow-Headers' 'Authorization,PATCH';
proxy_cookie_domain host $host;
proxy_pass http://couchdb/;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#I tried to use this one too
# location /_session {
# proxy_pass http://couchdb/_session;
# proxy_redirect off;
# proxy_buffering off;
# proxy_set_header Host $host;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# }
}
我最终收到了服务器的响应(http:// web_server_ip / couchdb / _session)
但是响应中没有Set-Cookie标头,因此(据我了解),当我的应用程序尝试将下一个请求发送到数据库时,我收到401未经授权的响应
在此先感谢您的帮助:)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)