0

I want to add CORS headers to my nginx responses in ddev.

I have added a "cors.conf" in ".ddev/nginx", which is definitely included, since the web container crashes when the configuration file is broken. I have tried different versions, with location, if-conditions and so on, but there was no difference - except for a broken state of the configuration file. In this case I got an error from the web container.

cors.conf (right now)

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods *;
add_header Access-Control-Allow-Headers *;
add_header Access-Control-Allow-Credentials *;

I expected the headers to show up on every request, but they don't.

Can someone provide a working nginx configuration for ddev with CORS headers?

Edit:

Some system information: * Windows 8.1 * Docker-Toolbox with Docker 18.09.0 * ddev 1.8.0

  • I see a significant conversation about CORS and ddev at https://github.com/drud/ddev/pull/1228 - What's different about your situation? – rfay Aug 06 '19 at 01:54
  • Your cors.conf does fine with this... it's just that it's the actually the *router's* headers that you're seeing and studying, and the ddev-webserver's nginx headers don't seem to be passed along. Here's what I see with your cors.conf when I hit the *https://127.0.0.1* URL (see ddev describe for the direct not-through-router URL) https://www.evernote.com/l/AA_HT-QhE-xEULKvmI9Ll9u-NCD5B_tC1pw – rfay Aug 06 '19 at 03:24
  • 1
    I wanted to check that today and it seems to work now (even on the hostnames). I don't know what happened, as well as https://github.com/drud/ddev/pull/1228#issuecomment-435210811 describes it. I can only assume that restarting the project wasn't enough for the headers to take effect (within the router?), so after restarting my whole machine it did. – Almost Night Aug 06 '19 at 10:56

0 Answers0