2016-11-27 10 views
5

मैं अपने सर्वर पर इस त्रुटि प्राप्त हो रही: [error] Could not check origin for Phoenix.Socket transport.कस्टम डोमेन WebSocket हाथ मिलाना त्रुटि

मैं एक फीनिक्स और जे एस एप्लिकेशन Heroku पर चल myapp.herokuapp.com पर ठीक है कि चैनलों का उपयोग करता है।

मैं heroku custom domain निर्देशों का पालन किया और करने के लिए अपने prod.exs config बदलने के बाद अब मेरे ऐप की जावास्क्रिप्ट लोड नहीं कर सकता: से url: [scheme: "https", host: "myapp.com", port: 443] : url: [scheme: "https", host: "myapp.herokuapp.com", port: 443]

मैं कस्टम डोमेन का उपयोग करके ऐप पर जाकर जब इस त्रुटि जेएस मिल myapp.com:

WebSocket connection to 'wss://myapp.com/socket/websocket?token=undefined&vsn=1.0.0' failed: Error during WebSocket handshake: Unexpected response code: 400 

साथ Heroku लॉग्स:

2016-11-27T03:27:52.259269+00:00 heroku[router]: at=info method=GET path="/socket/websocket?token=undefined&vsn=1.0.0" host=myapp.com request_id=94bd304b-e8f5-44aa-aff0-9336425e40b3 fwd="2601:602:9301:2b00:3c91:6660:9593:ad2c,2601:0602:9301:2b00:3c91:6660:9593:ad2c,108.162.245.66" dyno=web.1 connect=1ms service=1ms status=400 bytes=119 
2016-11-27T03:28:03.671267+00:00 heroku[router]: at=info method=GET path="/socket/websocket?token=undefined&vsn=1.0.0" host=myapp.herokuapp.com request_id=71483e0c-8f2a-4485-8506-5931513de1fb fwd="50.159.116.207" dyno=web.1 connect=0ms service=1ms status=403 bytes=195 
2016-11-27T03:28:03.650158+00:00 app[web.1]: 03:28:03.649 [error] Could not check origin for Phoenix.Socket transport. 
2016-11-27T03:28:03.650173+00:00 app[web.1]: 
2016-11-27T03:28:03.650174+00:00 app[web.1]: This happens when you are attempting a socket connection to 
2016-11-27T03:28:03.650175+00:00 app[web.1]: a different host than the one configured in your config/ 
2016-11-27T03:28:03.650175+00:00 app[web.1]: files. For example, in development the host is configured 
2016-11-27T03:28:03.650176+00:00 app[web.1]: to "localhost" but you may be trying to access it from 
2016-11-27T03:28:03.650177+00:00 app[web.1]: "127.0.0.1". To fix this issue, you may either: 
2016-11-27T03:28:03.650178+00:00 app[web.1]: 
2016-11-27T03:28:03.650178+00:00 app[web.1]: 1. update [url: [host: ...]] to your actual host in the 
2016-11-27T03:28:03.650179+00:00 app[web.1]:  config file for your current environment (recommended) 
2016-11-27T03:28:03.650179+00:00 app[web.1]: 
2016-11-27T03:28:03.650180+00:00 app[web.1]: 2. pass the :check_origin option when configuring your 
2016-11-27T03:28:03.650180+00:00 app[web.1]:  endpoint or when configuring the transport in your 
2016-11-27T03:28:03.650181+00:00 app[web.1]:  UserSocket module, explicitly outlining which origins 
2016-11-27T03:28:03.650182+00:00 app[web.1]:  are allowed: 
2016-11-27T03:28:03.650182+00:00 app[web.1]: 
2016-11-27T03:28:03.650183+00:00 app[web.1]:   check_origin: ["https://example.com", 
2016-11-27T03:28:03.650184+00:00 app[web.1]:      "//another.com:888", "//other.com"] 

जब मैं यात्रा कर myapp.herokuapp.com जे एस त्रुटि थोड़ा अलग है:

WebSocket connection to 'wss://myapp.herokuapp.com/socket/websocket?token=undefined&vsn=1.0.0' failed: Error during WebSocket handshake: Unexpected response code: 403 

साथ Heroku लॉग्स:

2016-11-27T03:31:31.615163+00:00 heroku[router]: at=info method=GET path="/socket/websocket?token=undefined&vsn=1.0.0" host=myapp.herokuapp.com request_id=d43b57da-6aef-426b-ba69-7706c95ccc6d fwd="50.159.116.207" dyno=web.1 connect=0ms service=1ms status=403 bytes=195 
2016-11-27T03:31:31.580305+00:00 app[web.1]: 03:31:31.579 [error] Could not check origin for Phoenix.Socket transport. 
2016-11-27T03:31:31.580319+00:00 app[web.1]: 
2016-11-27T03:31:31.580320+00:00 app[web.1]: This happens when you are attempting a socket connection to 
2016-11-27T03:31:31.580321+00:00 app[web.1]: a different host than the one configured in your config/ 
2016-11-27T03:31:31.580322+00:00 app[web.1]: files. For example, in development the host is configured 
2016-11-27T03:31:31.580322+00:00 app[web.1]: to "localhost" but you may be trying to access it from 
2016-11-27T03:31:31.580323+00:00 app[web.1]: "127.0.0.1". To fix this issue, you may either: 
2016-11-27T03:31:31.580324+00:00 app[web.1]: 
2016-11-27T03:31:31.580325+00:00 app[web.1]: 1. update [url: [host: ...]] to your actual host in the 
2016-11-27T03:31:31.580325+00:00 app[web.1]:  config file for your current environment (recommended) 
2016-11-27T03:31:31.580326+00:00 app[web.1]: 
2016-11-27T03:31:31.580326+00:00 app[web.1]: 2. pass the :check_origin option when configuring your 
2016-11-27T03:31:31.580327+00:00 app[web.1]:  endpoint or when configuring the transport in your 
2016-11-27T03:31:31.580327+00:00 app[web.1]:  UserSocket module, explicitly outlining which origins 
2016-11-27T03:31:31.580328+00:00 app[web.1]:  are allowed: 
2016-11-27T03:31:31.580329+00:00 app[web.1]: 
2016-11-27T03:31:31.580329+00:00 app[web.1]:   check_origin: ["https://example.com", 
2016-11-27T03:31:31.580330+00:00 app[web.1]:      "//another.com:888", "//other.com"] 

जब मैं url: [scheme: "https", host: "myapp.herokuapp.com", port: 443] के रूप में मेरे config रखने मैं कोई त्रुटि जब मिल myapp.herokuapp.com पर जाकर, लेकिन जब मैं myapp.com पर जाता हूं तो मुझे जेएस कंसोल में निम्न त्रुटि मिलती है:

WebSocket connection to 'wss://myapp.com/socket/websocket?token=undefined&vsn=1.0.0' failed: Error during WebSocket handshake: Unexpected response code: 403 

साथ Heroku लॉग्स:

2016-11-27T03:34:55.671996+00:00 heroku[router]: at=info method=GET path="/socket/websocket?token=undefined&vsn=1.0.0" host=myapp.com request_id=ab595797-26ab-4952-ac77-2ab31bf18384 fwd="50.159.116.207,50.159.116.207,108.162.245.248" dyno=web.1 connect=0ms service=1ms status=403 bytes=214 
2016-11-27T03:34:55.661334+00:00 app[web.1]: This happens when you are attempting a socket connection to 
2016-11-27T03:34:55.661335+00:00 app[web.1]: a different host than the one configured in your config/ 
2016-11-27T03:34:55.661321+00:00 app[web.1]: 03:34:55.661 [error] Could not check origin for Phoenix.Socket transport. 
2016-11-27T03:34:55.661333+00:00 app[web.1]: 
2016-11-27T03:34:55.661347+00:00 app[web.1]: files. For example, in development the host is configured 
2016-11-27T03:34:55.661348+00:00 app[web.1]: to "localhost" but you may be trying to access it from 
2016-11-27T03:34:55.661349+00:00 app[web.1]: "127.0.0.1". To fix this issue, you may either: 
2016-11-27T03:34:55.661350+00:00 app[web.1]: 1. update [url: [host: ...]] to your actual host in the 
2016-11-27T03:34:55.661352+00:00 app[web.1]:  endpoint or when configuring the transport in your 
2016-11-27T03:34:55.661351+00:00 app[web.1]:  config file for your current environment (recommended) 
2016-11-27T03:34:55.661349+00:00 app[web.1]: 
2016-11-27T03:34:55.661351+00:00 app[web.1]: 
2016-11-27T03:34:55.661352+00:00 app[web.1]: 2. pass the :check_origin option when configuring your 
2016-11-27T03:34:55.661354+00:00 app[web.1]:  are allowed: 
2016-11-27T03:34:55.661355+00:00 app[web.1]: 
2016-11-27T03:34:55.661353+00:00 app[web.1]:  UserSocket module, explicitly outlining which origins 
2016-11-27T03:34:55.661355+00:00 app[web.1]:   check_origin: ["https://example.com", 
2016-11-27T03:34:55.661356+00:00 app[web.1]:      "//another.com:888", "//other.com"] 

मैं गलत पर check_origin स्थापित करने की कोशिश की लेकिन यह या तो काम नहीं कर रहा। Myapp.com पर जाकर Heroku लॉग अब त्रुटि नहीं दिखाते हैं।

heroku[router]: at=info method=GET path="/socket/websocket?token=undefined&vsn=1.0.0" host=myapp.com request_id=379b61c9-94be-4a1c-ac43-419e9554ac51 fwd="2601:602:9301:2b00:3c91:6660:9593:ad2c,2601:0602:9301:2b00:3c91:6660:9593:ad2c,108.162.245.122" dyno=web.1 connect=1ms service=1ms status=400 bytes=119 

लेकिन मैं अभी भी जे एस कंसोल में इस हो रही है: क्या यह लायक है के लिए मैं:

WebSocket connection to 'wss://myapp.com/socket/websocket?token=undefined&vsn=1.0.0' failed: Error during WebSocket handshake: Unexpected response code: 400 

मेरे मेरे ऐप की समाप्ति बिंदु

config :my_app, MyApp.Endpoint, 
    http: [port: {:system, "PORT"}], 
    url: [scheme: "https", host: "myapp.com", port: 443], 
    check_origin: false, 
    force_ssl: [rewrite_on: [:x_forwarded_proto]], 
    cache_static_manifest: "priv/static/manifest.json", 
    secret_key_base: System.get_env("SECRET_KEY_BASE") 

संपादित के लिए पूरी config मैं अपने डीएनएस के लिए क्लाउडफ्लेयर का उपयोग कर रहा हूं और एसएसएल विकल्प पूर्ण हो गया है।


संपादित 2: अगर मैं अपने config में check_origin: false रखने मैं myapp.com लोड कर सकते हैं और मैं अपने सॉकेट बदल जाते हैं।js फ़ाइल से:

let socket = new Socket("/socket", {params: {token: window.userToken}}) 

रहे हैं:

let socket = new Socket("wss://myapp.herokuapp.com/socket", {params: {token: window.userToken}}) 

जब से मैं check_origin झूठी रखने के लिए मैं इसे इस पर अपडेट करने की कोशिश की नहीं करना चाहती:

url: [scheme: "https", host: "myapp.com", port: 443], 
    check_origin: ["myapp.com", "myapp.herokuapp.com", "//myapp.com", "//myapp.herokuapp.com"], 

इन के साथ एप्लिकेशन को फिर कंपाइल करने के बाद नई सेटिंग्स यह मेरे कंसोल में इस जे एस त्रुटि के साथ छोड़ देता है जब मैं यात्रा करने के लिए कोशिश myapp.com:

WebSocket connection to 'wss://myapp.herokuapp.com/socket/websocket?token=undefined&vsn=1.0.0' failed: Error during WebSocket handshake: Unexpected response code: 503 
+0

मैं एक ही समस्या हो रही है (मेरे config के बाकी तुम्हारा के रूप में सिर्फ एक ही है)। मैं herokuapp यूआरएल का उपयोग कर और उस त्रुटि मिलती है, लेकिन मैं नहीं तो विकास मोड शायद मुद्दों होता js में Heroku यूआरएल को हार्डकोड नहीं करना चाहता हूँ। – Homan

+0

मुझे लगता है कि आप गलत जगह पर 'check_origin' रखा। यह 'चैनल/user_socket.ex' में डाल दिया,' परिवहन में: websocket' अनुभाग –

उत्तर

0

सबसे पहले समस्या Heroku और CloudFlare उपयोग करने के साथ निहित है। इस आलेख में कहा गया है कि इसे कस्टम यूआरएल के साथ नहीं किया जा सकता है, आप इसे केवल डिफ़ॉल्ट हेरोकू यूआरएल https://support.cloudflare.com/hc/en-us/articles/205893698-Configure-Cloudflare-and-Heroku-over-HTTPS

के साथ उपयोग कर सकते हैं, जो क्लाउडफ्लेयर का उपयोग किए बिना मुझे भी समस्याएं आ रही थीं। क्या मेरे लिए काम किया था - यूआरएल आप तक पहुँच रहे हैं का पूरा पथ को check_origin पैरामीटर सेट। मेरे लिए मैं भी www उपयोग कर रहा था, इसलिए मेरे config इस

url: [scheme: "https", host: "myapp.com", port: 443], 
check_origin: [ 
    "https://myapp.com", 
    "https://www.myapp.com" 
], 

की तरह दिखाई देता

संबंधित मुद्दे