php – Nginx不会将Cookie传递给代理

前端之家收集整理的这篇文章主要介绍了php – Nginx不会将Cookie传递给代理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个cookie集适用于所有子域名.example.com.我有Nginx ajax调用通过proxy_pass,但cookie不会保留.我的配置如下所示:

server {
    listen   80;
    server_name  www.example.com;

    location / {
        root   /data/sites/www.example.com/widgets/public_html;
        index  index.PHP index.html index.htm;
        try_files $uri $uri/ /index.PHP?rt=$uri&$args;
    }

    location ~ .PHP${
      root          /data/sites/www.example.com/site/public_html;
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param REQUEST_URI    $uri;
      fastcgi_index  index.PHP;
      include        fastcgi_params;
      fastcgi_param ENV staging;
    }


    location /api {
        proxy_pass_header  Set-Cookie;
        proxy_cookie_domain $host example.com;
        proxy_pass_header  P3P;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Fowarded-Host $host;
        proxy_pass http://api.example.com/;
        proxy_connect_timeout 1;
    }

}

但是当我检查ajax调用时,它看起来像这样:

上面的图片显示正在发送的cookie应该是.example.com时具有N / A域.它适用于我的Apache / PHP配置,但不适用于我的Nginx / PHP配置.我究竟做错了什么?

最佳答案
我认为你应该更换

server_name  www.example.com;

有:

server_name  www.example.com example.com *.example.com;
原文链接:https://www.f2er.com/nginx/434780.html

猜你在找的Nginx相关文章