Nginx Does Not Pass Cookies To Proxy

自作多情 提交于 2020-01-14 07:46:06

问题


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;
    }

}

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

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?


回答1:


I think you should replace

server_name  www.example.com;

with:

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


来源:https://stackoverflow.com/questions/22175000/nginx-does-not-pass-cookies-to-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!