Cookie 在本地主机上运行良好,但在 VPS 上不起作用

Cookies work great on localhost but does not work on VPS

我正在使用 nodejs 和 angularjs 1.6.4。在 localhost 上一切正常,但是当我通过 Github 将我的代码推送到 Digital Ocean droplet 时,cookie 不起作用。我保存到 cookie 中的所有内容都不会出现在 Cookie 存储中。为什么会这样?

更新 当我在 VPS 上登录页面时出现警告:"This page includes a password or credit card input in a non-secure context. A warning has been added to the URL bar"

相关代码如下:

$scope.login = function () {

      UserService.login($scope.user).then(function (result) {
        if (result.data.success) {
          $rootScope.userLogin = result.data.data.name;

          //------------------
          var day = new Date();
          day.setDate(day.getDay() + 30);

          var options = {
            domain: "localhost",
            httpOnly: true,
            expires: day
          };
          // cookie does not work, nothing in Cookie Storage
          // but it works perfectly on localhost
          $cookies.put('token', result.data.data.token, options);
          $cookies.put('name', result.data.data.name, options);
          // the session storage work greatly
          $sessionStorage.user = 'heheeheh';
          flash.success = result.data.message;
          $state.go('home');
        } else {
          flash.error = result.data.message;
        }
      });
    } 

更新:

我在 amazon ec2 上创建了另一个 VPS,但它仍然不起作用。

我发现只需将 domain 选项从 localhost 更改为服务器的 IP