express - #nginx 反向代理本地cookie 無法攜帶上去
問題描述
1.在coding page 部署了一個(gè)項(xiàng)目比如地址這樣http://app.coding.me/film,接口在第三方服務(wù)器地址http://xxx.com/v4/api/..2.現(xiàn)在在阿里的服務(wù)器上用nginx反向代理接口轉(zhuǎn)發(fā),解決了跨域,但發(fā)現(xiàn)在在http://app.coding.me/film域名發(fā)送請求本地cookie無法發(fā)送給第三方服務(wù)器。而且request headers 無法攜帶cookie 上去 withCredentials:true這是我的代理配置請問有毛病嗎
listen 80;server_name api.server.top;//#接口請求域名location /api { add_header ’Access-Control-Allow-Origin’ http://app.coding.me; add_header ’Access-Control-Allow-Credentials’ ’true’; add_header ’Access-Control-Allow-Methods’ ’GET, POST, OPTIONS’; proxy_cookie_domain xxx.com app.coding.me;#重新改寫第三方返回cookie domain proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Nginx-Proxy true; proxy_set_header Connection ''; proxy_set_header Referer xxx.com; proxy_set_header Host $proxy_host; proxy_pass http://xxx.com/v4/api/;#目標(biāo)接口地址 }
#responseHTTP/1.1 200 OKServer: nginx/1.10.1Date: Thu, 25 May 2017 07:53:23 GMTContent-Type: application/json; charset=utf-8Content-Length: 1761Connection: keep-aliveX-Powered-By: MaizuoMobileWeb/4.27.10Set-Cookie: cityId=10; Max-Age=2592000; Domain=.xxx.com; Path=/; Expires=Sat, 24 Jun 2017 07:55:19 GMTSet-Cookie: cityName=%E6%B7%B1%E5%9C%B3; Max-Age=2592000; Domain=.xxx.com; Path=/; Expires=Sat, 24 Jun 2017 07:55:19 GMTETag: W/'JNVa2eLxZZXafos18vYaFA=='Access-Control-Allow-Origin: http://app.coding.meAccess-Control-Allow-Credentials: trueAccess-Control-Allow-Methods: GET, POST, OPTIONS
#requestHost: api.server.topConnection: keep-aliveAccept: application/json, text/plain, */*Origin: http://app.coding.meUser-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Mobile Safari/537.36Referer: http://app.coding.me/film/Accept-Encoding: gzip, deflate, sdchAccept-Language: zh-CN,zh;q=0.8,en;q=0.6,und;q=0.4,zh-TW;q=0.2,ja;q=0.2Cookie: cityId=10; cityName=%E6%B7%B1%E5%9C%B3;瀏覽器中cookie cityId=13 cityName='%E5%B9%BF%E5%B7%9E' 都變了,request 和 response cookie 始終不變。
圖中 cookie Domain N/A啥意思?
問題解答
回答1:proxy_cookie_domain xxx.com app.coding.me;#重新改寫第三方返回cookie domain 這個(gè)應(yīng)該有問題
回答2:就是有問題,不行你可以把cookie 給前端 前端再通過js 設(shè)置cookie
相關(guān)文章:
1. angular.js - angular內(nèi)容過長展開收起效果2. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””3. docker容器呢SSH為什么連不通呢?4. 前端 - ng-view不能加載進(jìn)模板5. android clickablespan獲取選中內(nèi)容6. debian - docker依賴的aufs-tools源碼哪里可以找到啊?7. python - from ..xxxx import xxxx到底是什么意思呢?8. nignx - docker內(nèi)nginx 80端口被占用9. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?10. docker網(wǎng)絡(luò)端口映射,沒有方便點(diǎn)的操作方法么?
