【发布时间】:2015-10-07 04:54:25
【问题描述】:
我已将 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 应用程序的请求,我收到以下错误:
跨域请求被阻止:同源策略不允许读取 远程资源
我在 docker 容器中使用 nginx 在同一台 linux 机器上托管了我的应用程序。 我尝试通过在 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 时,我会得到“好的”。
非常感谢任何帮助。 谢谢。
【问题讨论】:
-
如果您使用
curl -i http://10.x.x.120:8500,标题是否实际上是Access-Control-Allow-Origin: *? -
No is 没有在标题中显示。这就是我得到的全部 http/1.1 200 ok - content-type:text/plain - content-length: 2
-
那么看来你的nginx配置有问题。 See this for a sample CORS config for nginx.
-
是的,我尝试了这些设置,但这不起作用。我仍然得到相同的标题信息。
标签: angularjs linux http nginx cors