To be able to allow EventSource special nginx directives are needed.
Currently it is only possible to change the configuration for everything. I was wondering if it is possible to somehow set special directives for different endpoints.
To be complete the needed directives for EventSource:
proxy_buffering off;
proxy_cache off;
proxy_set_header Host $host;
proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding off;
this is probably best done as a plugin
Plugins cannot change the nginx configuration.
What about the response-transformer plugin?
Is the plugin executed before the response is handoffed to nginx?
If so you could disable proxy_buffering using the X-Accel-Buffering as described in the nginx docs:
Buffering can also be enabled or disabled by passing “yes” or “no” in the “X-Accel-Buffering” response header field.
@thibaultCha Would be great if you could clarify the question regarding the execution order. Thanx!
Plugins are executed in nginx since Kong is Openresty. I don't know if that would work.
But are they executed before nginx relevant headers are processed or not?
I do not know.
Ok, thank you.
Just wanted to mention that i could not set a header (X-Accel-Buffering in my case) that would change the bevaior of nginx using the response-transformer plugin.
The solution I came up with for this was to edit the nginx config in the kong.yml to catch the location for the event source api being called and add the proper settings. kong will still apply plugins and such onto the api, and your eventsource will work.
The wrinkle / annoyance here is nginx doesn't support inheritance of nested locations (as far as I can tell / read up on, I'm no nginx guru at all), so you will have to copy the stuff from the root location which contains some of the kong configuration stuff into your new location.
Example:
Let's say you have an eventsource api running on your_kong_server/some_api/events
The nginx config in your kong.yml file is structured as
location / {
###
# configuration stuff
###
}
You will want to add / do
location / {
# copy all the kong related settings from here into the block below
location /some_api/events {
# copy all kong related settings from above into this block, along with:
# settings to get event source working
proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_buffering off;
proxy_cache off;
}
}
Yes this is needed fro couchdb stuff like replication etc.
https://cwiki.apache.org/confluence/display/COUCHDB/Nginx+as+a+proxy
This is long out of date; cases like this can simply use a custom Nginx config file (https://docs.konghq.com/1.0.x/configuration/#custom-nginx-templates--embedding-kong). Feature-specific cases can definitely be brought up again in the future, but the concept of "we need a custom Nginx directive for X feature" can be handled with a custom template, or via directive injection: https://docs.konghq.com/1.0.x/configuration/#injecting-nginx-directives
Most helpful comment
Yes this is needed fro couchdb stuff like replication etc.
https://cwiki.apache.org/confluence/display/COUCHDB/Nginx+as+a+proxy