# Failed to start elasticsearch when enable CORS

**URL:** https://discuss.elastic.co/t/failed-to-start-elasticsearch-when-enable-cors/38702
**Category:** Elasticsearch
**Created:** [January 8, 2016, 8:24am UTC](https://discuss.elastic.co/t/failed-to-start-elasticsearch-when-enable-cors/38702 "2016-01-08T08:24:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Weizhen\_Yan](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@Weizhen\_Yan](https://discuss.elastic.co/u/Weizhen_Yan)
#### Post date: [January 8, 2016, 8:24am UTC](https://discuss.elastic.co/t/failed-to-start-elasticsearch-when-enable-cors/38702/1 "2016-01-08T08:24:55Z")

</div>

Tried to enable HTTP CORS on ES, but after I added  
http.cors.enabled: true  
http.cors.allow-origin: "\*"  
to elasticsearch.yml, ES can't start and I got this error:

```
Exception in thread "main" SettingsException[Failed to load settings from [elasticsearch.yml]]; nested: ParserException[while parsing a block mapping
 in 'reader', line 17, column 1:
    cluster.name: elasticsearch_roccia
    ^
expected <block end>, but found BlockMappingStart
 in 'reader', line 59, column 3:
      http.cors.enabled: true
      ^
];
Likely root cause: while parsing a block mapping
 in 'reader', line 17, column 1:
    cluster.name: elasticsearch_roccia
    ^
expected <block end>, but found BlockMappingStart
 in 'reader', line 59, column 3:
      http.cors.enabled: true
  ^
at com.fasterxml.jackson.dataformat.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:570)
at com.fasterxml.jackson.dataformat.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
at com.fasterxml.jackson.dataformat.yaml.snakeyaml.parser.ParserImpl.getEvent(ParserImpl.java:168)
at com.fasterxml.jackson.dataformat.yaml.YAMLParser.nextToken(YAMLParser.java:342)
at org.elasticsearch.common.xcontent.json.JsonXContentParser.nextToken(JsonXContentParser.java:53)
at org.elasticsearch.common.settings.loader.XContentSettingsLoader.serializeObject(XContentSettingsLoader.java:99)
at org.elasticsearch.common.settings.loader.XContentSettingsLoader.load(XContentSettingsLoader.java:67)
at org.elasticsearch.common.settings.loader.XContentSettingsLoader.load(XContentSettingsLoader.java:45)
at org.elasticsearch.common.settings.loader.YamlSettingsLoader.load(YamlSettingsLoader.java:46)
at org.elasticsearch.common.settings.Settings$Builder.loadFromStream(Settings.java:1074)
at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1061)
at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:88)
at org.elasticsearch.common.cli.CliTool.<init>(CliTool.java:107)
at org.elasticsearch.common.cli.CliTool.<init>(CliTool.java:100)
at org.elasticsearch.bootstrap.BootstrapCLIParser.<init>(BootstrapCLIParser.java:48)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:241)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)

```

Refer to the log for complete error details.

Need some help ! Thank you

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [January 8, 2016, 8:36am UTC](https://discuss.elastic.co/t/failed-to-start-elasticsearch-when-enable-cors/38702/2 "2016-01-08T08:36:56Z")

</div>

Looks like your configuration file isn't valid YAML. Pay attention to the indentation. If you post the configuration file here we can help you debug it, but make sure you format it as code using the toolbar button.

---

<div class="post-metadata">

### Author: ![Weizhen\_Yan](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@Weizhen\_Yan](https://discuss.elastic.co/u/Weizhen_Yan)
#### Post date: [January 8, 2016, 9:17am UTC](https://discuss.elastic.co/t/failed-to-start-elasticsearch-when-enable-cors/38702/4 "2016-01-08T09:17:25Z")

</div>

> [@magnusbaeck](#):
>
> Looks like your configuration file isn't valid YAML. Pay attention to the indentation. If you post the configuration file here we can help you debug it, but make sure you format it as code using the toolbar button.

Thank you !  
[http://pastie.org/10677234](http://pastie.org/10677234)  
here is my elasticsearch.yml, always can't make code style show correctly in the post... sry for any inconvenience .

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [January 8, 2016, 9:17am UTC](https://discuss.elastic.co/t/failed-to-start-elasticsearch-when-enable-cors/38702/5 "2016-01-08T09:17:53Z")

</div>

Here's the problem:

```auto
...
# Set a custom port for HTTP:
#
# http.port: 9200
  http.cors.enabled: true
  http.cors.allow-origin: "*"
#
...

```

Don't indent the http.cors.\* lines.

---

<div class="post-metadata">

### Author: ![Weizhen\_Yan](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@Weizhen\_Yan](https://discuss.elastic.co/u/Weizhen_Yan)
#### Post date: [January 8, 2016, 9:31am UTC](https://discuss.elastic.co/t/failed-to-start-elasticsearch-when-enable-cors/38702/6 "2016-01-08T09:31:09Z")

</div>

> [@magnusbaeck](#):
>
> Here's the problem:
> 
> ```auto
> ...
> # Set a custom port for HTTP:
> #
> # http.port: 9200
> http.cors.enabled: true
> http.cors.allow-origin: "*"
> #
> ...
> 
> ```
> 
> Don't indent the http.cors.\* lines.

what do u mean by dont indent? like this?

```auto
...
# Set a custom port for HTTP:
#
# http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
#
...

```

---

<div class="post-metadata">

### Author: ![Weizhen\_Yan](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@Weizhen\_Yan](https://discuss.elastic.co/u/Weizhen_Yan)
#### Post date: [January 8, 2016, 9:38am UTC](https://discuss.elastic.co/t/failed-to-start-elasticsearch-when-enable-cors/38702/7 "2016-01-08T09:38:32Z")

</div>

> [@magnusbaeck](#):
>
> Here's the problem:
> 
> ```auto
> ...
> # Set a custom port for HTTP:
> #
> # http.port: 9200
> http.cors.enabled: true
> http.cors.allow-origin: "*"
> #
> ...
> 
> ```
> 
> Don't indent the http.cors.\* lines.

fix it!! thank you! I should read some yml doc - -!

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [January 8, 2016, 10:28am UTC](https://discuss.elastic.co/t/failed-to-start-elasticsearch-when-enable-cors/38702/8 "2016-01-08T10:28:37Z")

</div>

Yes, exactly. No whitespace at the beginning of the line.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 11:26pm UTC](https://discuss.elastic.co/t/failed-to-start-elasticsearch-when-enable-cors/38702/9 "2017-07-05T23:26:05Z")

</div>


