gpt4 book ai didi

angularjs - Angular 在使用资源时不使用 cookie

转载 作者:行者123 更新时间:2023-11-28 23:33:01 25 4
gpt4 key购买 nike

我遇到了很多话题,但找不到我的问题所在。

我有一个正在运行的应用程序:http://example.com:8081/app/

我有一个 Angular 应用:http://example.com:8081/app/angular/http://example.com:8081/app/rest/ 上的休息 api

我做了一个 nginx 服务器来代理这个域,比如:

http://angular.example.com =>代理 Angular 应用程序和 http://rest.example.com => 代理其余的 api。

Booth 正在工作,并且正在通信,但我在存储 rest.exemple.com 发送的 cookie 时遇到了问题

登录服务后有响应头:

Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin: "http://angular.example.com"
Connection:keep-alive
Content-Type:application/json
Date:Tue, 20 Jan 2015 17:52:19 GMT
Server:nginx/1.2.1
Set-Cookie:JSESSIONID=0F69455E4475CDFBF7D1C01BC4C1D121; Path=/app/; HttpOnly
Transfer-Encoding:chunked
Vary:Origin

然后 angular 不要使用这个 JSESSIONID 进行其他调用...

我已经设置了 $httpProvider.defaults.withCredentials = true;,没有任何改变...

有什么想法吗?

编辑:当我输入 url 时工作:http://example.com:8080/app/rest/但不是 http://rest.example.com/

这是我的 nginx 配置文件:

server {

listen 80;
server_name rest.example.com;
location / {
proxy_pass http://localhost:8081/app/rest/;
proxy_redirect 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;
}
}

@sergiocruz:document.cookie 不返回任何内容,并且还带有 http://example.com:8080/app/rest/

EDIT2:在这篇文章中使用 apache: How to properly set JSESSIONID cookie path behind reverse proxy

如果有人必须用 nginx 解决 :)

最佳答案

EDIT : working when I put as url : http://example.com:8080/app/rest/ but not with http://rest.example.com/

我不知道如何在 nginx( maybe it helps ) 上做到这一点,但据我了解,您的 cookie 应该包含下一个 header 字段 domain=.example.com 注意域掩码开头的点。或者您可以显式设置 domain=rest.example.com

关于angularjs - Angular 在使用资源时不使用 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28052128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com