I have configured Logstash 1.5.2 to consume http input on a linux machine.
This is my logstash input configuration:
input {
http {
host => "10.x.x.120"
port => "8500"
}
}
I can send data to logstash by using curl -XPOST from the linux machine.
But when I make a $http.post(url, postData); request from my angularJS application I get the following error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource
I have hosted my application on the same linux machine using nginx within a docker container. I have tried to configure nginx to allow CORS by adding the following lines to the nginx.conf:
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';
But still the error persists.
Also when I hit http://10.x.x.120:8500 from my browser address bar I get 'ok'.
Any help is highly appreciated. Thanks.
Cross-Origin Resource Sharing (CORS) errors occur when a server doesn't return the HTTP headers required by the CORS standard. To resolve a CORS error from an API Gateway REST API or HTTP API, you must reconfigure the API to meet the CORS standard.
Open a network tab in your console. In the response header look for the Access-Control-Allow-Origin header. If it does not exist then add it as a middleware in the way we discussed above. If it does exist then make sure there is no URL mismatch with the website.
If the CORS configuration isn't setup correctly, the browser console will present an error like "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at $somesite" indicating that the request was blocked due to violating the CORS security rules.
This could be a solution depending on your setup of Logstash in our case we use the http plugin to accept http calls. The http plugin plugin supports the following configuration options:
http {
response_headers {
"Content-Type" => "application/x-www-form-urlencoded",
"Access-Control-Allow-Origin" => "*",
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With