Nginx不会将Cookie传递给代理 [英] Nginx Does Not Pass Cookies To Proxy

查看:1170
本文介绍了Nginx不会将Cookie传递给代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a cookie set will work for all subdomains, .example.com . I have nginx ajax calls go through a proxy_pass but the cookie does not remain. My configuration looks like this:

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调用时,它看起来像这样:

But when I check the ajax call, it looks like this:

上图显示了发送的Cookie的域名应为.example.com,其域名为N/A.它适用于我的Apache/PHP配置,但不适用于我的nginx/php配置.我在做什么错了?

The picture above shows the cookie being sent has a domain of N/A when it should be .example.com . It works with my Apache/PHP configuration but does not with my nginx/php configuration. What am I doing wrong?

推荐答案

我认为您应该替换

server_name  www.example.com;

具有:

server_name  www.example.com example.com *.example.com;

这篇关于Nginx不会将Cookie传递给代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆