snibox / snibox

Self-hosted snippet manager

Home Page:https://snibox.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

enable cors with specified host

anxiaoyi opened this issue · comments

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.

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;
        }

no response - closed as deprecated