我已将 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 时从我的浏览器地址栏中,我得到“确定”。
非常感谢任何帮助。 谢谢。
最佳答案
这可能是一个解决方案,具体取决于您对 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/