Skip to content
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

enable cors with specified host #26

Closed
anxiaoyi opened this issue Jul 24, 2018 · 2 comments
Closed

enable cors with specified host #26

anxiaoyi opened this issue Jul 24, 2018 · 2 comments

Comments

@anxiaoyi
Copy link

2018_07_24_11_16_18

I deployed snibox to machine A, I have a nginx server deployed in machine B (https://machine-b-host.com). now I want to visit snibox by request the url (https://machine-b-host.com/snibox) by using nginx proxy_pass. Now, the GET request works well, but the /login POST request cannot works. seems like the snibox backend gives me a 422 status code, cause of the default CORS rejected policy.

I want to add my host (https://machine-b-host.com) to the CORS whitelist, so let the POST request works.
So which config should edit ? Thanks.

@piv-pav
Copy link

piv-pav commented Nov 2, 2018

First of all that would be nice to see the configuration you are currently running on yours nginx, and rails logs according this 422 response to at least understand why's that. I believe that might happed due to your snibox installation is using base URI /snibox, however you app ignores that fact and sending post request to /login instead of /snibox/login.

I'd try few options here:

  1. Set RAILS_RELATIVE_URL_ROOT environment variable to /snibox. You can do it using either .env file (check .env.production.sample) or using command RAILS_RELATIVE_URL_ROOT=/snibox rails server to start rails, or any other way provided by the method you starting your application (like Environment parameter inside SystemD unit file)
  2. Modify config.ru file to look like this
require_relative 'config/environment'

map '/snibox' do
    run Rails.application
end

Anyway this is my nginx config for proxying requests to the snibox running inside docker container which is working fine, however I don't use custom base URI for snibox:

location / {
        client_max_body_size 10M;
        proxy_pass http://<snibox_ip>:<snibox_port>;
		proxy_set_header  Host $host;
		proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header  X-Forwarded-Proto $scheme;
		proxy_set_header  X-Forwarded-Ssl off; # Optional
		proxy_set_header  X-Forwarded-Port $server_port;
		proxy_set_header  X-Forwarded-Host $host;
        }

@vavgustov
Copy link
Member

no response - closed as deprecated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants