angularjs - 向 logstash 发出发布请求时出现 CORS 错误

标签 angularjs linux http nginx cors

我已将 Logstash 1.5.2 配置为在 Linux 机器上使用 http 输入。

这是我的 logstash 输入配置:

input {
        http {
                host => "10.x.x.120"
                port => "8500"
        }
}

我可以在 linux 机器上使用 curl -XPOST 将数据发送到 logstash。

但是当我制作一个 $http.post(url, postData);从我的 angularJS 应用程序请求我收到以下错误:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource

我在同一台 linux 机器上使用 docker 容器中的 nginx 托管了我的应用程序。 我试图通过将以下行添加到 nginx.conf 来配置 nginx 以允许 CORS:

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

但是还是报错。

还有当我点击 http://10.x.x.120:8500 时从我的浏览器地址栏中,我得到“确定”。

enter image description here enter image description here 非常感谢任何帮助。 谢谢。

最佳答案

这可能是一个解决方案,具体取决于您对 Logstash 的设置在我们的例子中,我们使用 http接受http调用的插件。 The http plugin plugin supports the following configuration options :

http {
    response_headers {
        "Content-Type" => "application/x-www-form-urlencoded",
        "Access-Control-Allow-Origin" => "*",
    }
}

关于angularjs - 向 logstash 发出发布请求时出现 CORS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31476325/

相关文章:

python - HTTP请求相当于 `curl --user`参数?

json - 带有查询字符串的 POST 嵌套对象

python - 当没有文件重定向 url django 时,我的本地端口位于 127.0.0.1 :8000 always redirects to 127. 0.0.1:8000/myapp/lists

javascript - 如何将 ng-style 属性设置为等于对象值?

angularjs - 全局效用函数与指令

python - 内部服务器错误 : Target WSGI script cannot be loaded as Python module AND IOError: [Errno 2] No such file or directory: 'client_secrets.json'

linux - 如何获取当前附加的 screen session 名称?

javascript - 期望点击按钮打开文件浏览器

javascript - AngularJS - 在 POST 请求中使用 this 与 $scope

c - 为什么此代码包含 case 0 和 default?