title: How to set cookies with nginx proxy
body: <p>I have two server, the one name <code>page</code> listen to <code>127.0.0.1:8080</code>, the other name <code>api</code> listen to <code>127.0.0.1:8888</code>. The <code>api</code> can set cookie to response.
  The nginx config:</p>
  
  <pre><code>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;
      }
  </code></pre>
  
  <p>so I can request <code>127.0.0.1:8880/api/v1/user</code> proxy to <code>127.0.0.1:8888/user</code>.
  When I use:
  <code>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"
              }
          })
  </code>
  to login, the cookie registered on domain:<code>127.0.0.1</code>, path:<code>/api/v1/user</code>. But I want to registered on domain:<code>127.0.0.1</code>, path:<code>/</code>, so how can I do it? Is there anyone can help me?</p>
  
  <p>I try to add <code>proxy_cookie_path /api/v1/user /;</code> to <code>location 8888</code>, but it has no effect</p>