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ā)送請(qǐng)求本地cookie無法發(fā)送給第三方服務(wù)器。而且request headers 無法攜帶cookie 上去 withCredentials:true這是我的代理配置請(qǐng)問有毛病嗎
listen 80;server_name api.server.top;//#接口請(qǐng)求域名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. python - 如何正則字符串中的所有漢字2. mysql - 千萬級(jí)數(shù)據(jù)的表,添加unique約束,insert會(huì)不會(huì)很慢?3. python - oslo_config4. mysql - 分庫分表、分區(qū)、讀寫分離 這些都是用在什么場景下 ,會(huì)帶來哪些效率或者其他方面的好處5. mysql - 如何減少使用或者不用LEFT JOIN查詢?6. mysql - eclispe無法打開數(shù)據(jù)庫連接7. mysql 5個(gè)left關(guān)鍵 然后再用搜索條件 幾千條數(shù)據(jù)就會(huì)卡,如何解決呢8. mysql - jdbc的問題9. 圖片鏈接的地址怎么獲得的10. 視頻文件不能播放,怎么辦?
