lundi 20 novembre 2017

How to set cookies with ngnix proxy

I have two server, the one name page listen to 127.0.0.1:8080, the other name api listen to 127.0.0.1:8888. The api can set cookie to response. The ngnix config:

server {
    listen       8880;
    server_name  127.0.0.1;
    location / {
        proxy_pass http://127.0.0.1:8080;
        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;
    }

    location /api/v1/ {
        proxy_pass http://127.0.0.1:8888/;
        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;
    }

so I can request 127.0.0.1:8880/api/v1/user proxy to 127.0.0.1:8888/user. When I use: js $.ajax({ url: "/api/v1/user/login", type: "post", dataType: "json", data: JSON.stringify({"account": account, "password": password}), headers: {'Content-Type': 'application/json'}, success: function (res) { console.log(res.status); window.location = "/home" } }) to login, the cookie registered on domain:127.0.0.1, path:/api/v1/user. But I want to registered on domain:127.0.0.1, path:/, so how can I do it? Is there anyone can help me?




Aucun commentaire:

Enregistrer un commentaire