-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't get rack-cors to work in production environment using nginx/unicorn. #29
Comments
How is the middleware configured? |
In staging.rb:
|
What's the resource you're trying to access? Unfortunately, files in the public folder will be served directly from nginx, bypassing rails altogether. You can try altering your try_files command like this: # removed $uri
try_files $uri/index.html $uri.html @app; This will force all non-html resource through the app. Unfortunately, this will put extra load on the unicorn. You should be able to re-configure nginx to send just the resources you want through the app. Unfortunately, I've never done that before so I don't have any examples of how one would do this. |
It's an API controller route. The OPTIONS request gets in, but it returns a 404 because the rails app doesn't know what to do with it. |
I am having this exact same problem. Same stack (nginx+unicorn). Works great in via thin but not in production. I tried @cyu 's suggestion above and it had no effect. |
+1 |
1 similar comment
+1 |
I just did a clean Unicorn/Nginx install of the example Rails app (in examples/rails3) and was able to get my tests to pass. One thing to watch out for is to make sure Rack::Cors is inserted before the config.middleware.insert_before "ActionDispatch::Static", "Rack::Cors" do
...
end If you are still having issues, please provide some more information, like:
|
I'm having this same problem. It seems like nginx is not passing through the headers set by Rack::Cors. Output of
The route I'm hitting : The Nginx configuration:
|
Well, my problem turned out to be my own fault. I borked the regexes for some of my origins. Instead of |
Closing this as this is an old issue. I have made at fix wrt OPTIONS requests in the past. Feel free to reopen if this is still happening. |
It works in development, but setting the same in production or staging environments, rack-cors doesn't seem to add the appropriate headers. The preflight stuff looks okay.
Is there a specific problem with nginx configuration that causes the middleware to not work?
Here's my nginx config file:
The text was updated successfully, but these errors were encountered: