Cookies在本地主机上运行良好,但不适用于VPS

我正在使用nodejs和angularjs 1.6.4。 一切工作在本地主机很好,但是当我通过Github把我的代码推到数字海洋液滴,cookies不起作用。 我保存到Cookie的所有内容都不会显示在Cookie存储中。 为什么会发生?

更新当我进入VPS上的login页面时,出现一个警告: "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; } }); } 

更新:

我在亚马逊ec2上创build了另一个VPS,但它仍然无法正常工作。

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