[GH-ISSUE #26] enable cors with specified host #27

Closed
opened 2026-02-27 23:18:33 +03:00 by kerem · 2 comments
Owner

Originally created by @anxiaoyi on GitHub (Jul 24, 2018).
Original GitHub issue: https://github.com/snibox/snibox/issues/26

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.

Originally created by @anxiaoyi on GitHub (Jul 24, 2018). Original GitHub issue: https://github.com/snibox/snibox/issues/26 ![2018_07_24_11_16_18](https://user-images.githubusercontent.com/4382796/43114760-262c84a4-8f33-11e8-8e83-3abc5e8000b8.png) 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.
kerem closed this issue 2026-02-27 23:18:33 +03:00
Author
Owner

@piv-pav commented on GitHub (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;
        }
<!-- gh-comment-id:435324642 --> @piv-pav commented on GitHub (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](https://github.com/snibox/snibox/blob/master/.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`](https://github.com/snibox/snibox/blob/master/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: ```nginx 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; } ```
Author
Owner

@vavgustov commented on GitHub (Jan 29, 2019):

no response - closed as deprecated

<!-- gh-comment-id:458692721 --> @vavgustov commented on GitHub (Jan 29, 2019): no response - closed as deprecated
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/snibox#27
No description provided.