Error during WebSocket handshake: Unexpected response code: 403
joepstender opened this issue · comments
Elixir 1.6.3 (compiled with OTP 20)
Phoenix: 1.3
Drab: 0.8.1
While working fine locally, after pushing live I found Drab not working:
WebSocket connection to 'ws://myapp.nanoapp.io/socket/websocket?__drab_return= ... &__client_lib_version=6&vsn=2.0.0' failed: Error during WebSocket handshake: Unexpected response code: 403
Adding check_origin: false
to prod.exs fixed the issue.
See also: dwyl/learn-phoenix-framework#99 where I found the fix.
I don't think turning off check origin is a good idea. As stated in Phoenix docs, it is not recommended:
:check_origin - if we should check the origin of requests when the origin header is present. It defaults to true and, in such cases, it will check against the host value in YourApp.Endpoint.config(:url)[:host]. It may be set to false (not recommended) or to a list of explicitly allowed origins.
Better would be to proper configure:
- your proxy, see here
- your origin url in
prod.exs
:
config :myapp, url: [host: "tg.pl", port: 443]
Hi!. Just put application domain name, here is my example:
check_origin: ["//www.tentamen.eu"]