express - #nginx 反向代理本地cookie 無法攜帶上去
漂亮男人
漂亮男人 2017-05-27 17:44:59
0
2
1061

1.在coding page 部署了一個專案例如位址這樣http://app.coding.me/film,介面在第三方伺服器位址http://xxx.com/ v4/api/..
2.現在在阿里的伺服器上用nginx反向代理介面轉發,解決了跨域,但發現在在http:// app.coding.me/film網域傳送請求本地cookie無法傳送給第三方伺服器。而且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/;#目标接口地址
 }
#response
HTTP/1.1 200 OK
Server: nginx/1.10.1
Date: Thu, 25 May 2017 07:53:23 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 1761
Connection: keep-alive
X-Powered-By: MaizuoMobileWeb/4.27.10
Set-Cookie: cityId=10; Max-Age=2592000; Domain=.xxx.com; Path=/; Expires=Sat, 24 Jun 2017 07:55:19 GMT
Set-Cookie: cityName=%E6%B7%B1%E5%9C%B3; Max-Age=2592000; Domain=.xxx.com; Path=/; Expires=Sat, 24 Jun 2017 07:55:19 GMT
ETag: W/"JNVa2eLxZZXafos18vYaFA=="
Access-Control-Allow-Origin: http://app.coding.me
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, OPTIONS
#request
Host: api.server.top
Connection: keep-alive
Accept: application/json, text/plain, */*
Origin: http://app.coding.me
User-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.36
Referer: http://app.coding.me/film/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6,und;q=0.4,zh-TW;q=0.2,ja;q=0.2
Cookie: cityId=10; cityName=%E6%B7%B1%E5%9C%B3;

瀏覽器中cookie cityId=13 cityName="廣州" 都改變了,request 和 response cookie 永遠不變。

圖中 cookie Domain N/A啥意思?

漂亮男人
漂亮男人

全部回覆(2)
滿天的星座

proxy_cookie_domain xxx.com app.coding.me;#重新改寫第三方回傳cookie domain 這應該有問題

黄舟

就是有問題,
不行你可以把cookie 給前端 前端再透過js 設定cookie

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!