0

I've came across a lot of topic, but I can't find the issue of my problem.

I've an app working on : http://example.com:8081/app/

I've an angular app on : http://example.com:8081/app/angular/ and an rest api on http://example.com:8081/app/rest/

I've made an nginx server in order to proxy this domains like :

http://angular.example.com => proxy the angular app and http://rest.example.com => proxy the rest api.

Booth are working, and communicating but I've a problem to store the cookie sent by rest.exemple.com

There is the response header after an login service:

Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin: "http://angular.example.com"
Connection:keep-alive
Content-Type:application/json
Date:Tue, 20 Jan 2015 17:52:19 GMT
Server:nginx/1.2.1
Set-Cookie:JSESSIONID=0F69455E4475CDFBF7D1C01BC4C1D121; Path=/app/; HttpOnly
Transfer-Encoding:chunked
Vary:Origin

Then angular don't use this JSESSIONID to make anothers calls...

I've set $httpProvider.defaults.withCredentials = true;, doesn't change anything...

Any idea ?

EDIT : working when I put as url : http://example.com:8080/app/rest/ but not with http://rest.example.com/

There is my nginx conf:

server {

    listen 80;
    server_name rest.example.com;
    location / {
        proxy_pass  http://localhost:8081/app/rest/;
        proxy_redirect off;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}

@sergiocruz : document.cookie return nothing and also with http://example.com:8080/app/rest/

EDIT2 : Working with apache with this post : How to properly set JSESSIONID cookie path behind reverse proxy

If someone have to solution with nginx :)

Community
  • 1
  • 1
XciD
  • 2,537
  • 14
  • 40
  • Are you able to see the cookie you are looking for if you type `document.cookie` on your console? – sergiocruz Jan 20 '15 at 18:43
  • @sergiocruz just edited ;) – XciD Jan 20 '15 at 18:57
  • are you setting the cookie with a wild-card domain name? this makes a big difference... sub-domains are considered completely different domains unless you set the wild-card option. You are generating these cookies on the server side right? Make sure your server side app has that option set. – sergiocruz Jan 21 '15 at 00:01

1 Answers1

0

EDIT : working when I put as url : http://example.com:8080/app/rest/ but not with http://rest.example.com/

I don't know how to do that on nginx(maybe it helps) but as far as I understand your cookie should contain the next header field domain=.example.com Pay attention on a dot at the beginning of the domain mask. Or you can explicitly set domain=rest.example.com

MegaCasper
  • 1,871
  • 1
  • 13
  • 12