CORS error while making post request to logstash CORS error while making post request to logstash nginx nginx

CORS error while making post request to logstash


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" => "*",    }}


I was able to get this running by using reverse-proxy setting for nginx.

I modified my URL to be as follows:http://10.x.x.120/logs

And then made the following changes to the nginx.conf file:

location^~ /logs {    proxy_pass http://10.x.x.120:8500; }

Now when ever my application makes an HTTP POST request to http://10.x.x.120:8500/logs it is redirected to http://10.x.x.120:8500.

Voila!! Logstash gets the data because it is listening to port 8500.


you need not only to configure the POST/GET but OPTIONS as well, this is the configuration that I've in production and is working

## Wide-open CORS config for nginx#location / {     if ($request_method = 'OPTIONS') {        add_header 'Access-Control-Allow-Origin' '*';        #        # Om nom nom cookies        #        add_header 'Access-Control-Allow-Credentials' 'true';        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';        #        # Custom headers and headers various browsers *should* be OK with but aren't        #        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';        #        # Tell client that this pre-flight info is valid for 20 days        #        add_header 'Access-Control-Max-Age' 1728000;        add_header 'Content-Type' 'text/plain charset=UTF-8';        add_header 'Content-Length' 0;        return 200;     }     if ($request_method = 'POST') {        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';     }     if ($request_method = 'GET') {        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';     }}