zyro23 / grails-spring-websocket

93 stars 28 forks source link

/stomp/info 404 error in production but not development mode #68

Closed jonmor51 closed 4 years ago

jonmor51 commented 4 years ago

I have the plugin working fine in development mode, without error. In production, I deploy the Grails application behind a nginx reverse proxy server, which initially gave me a bunch of problems which I managed to solve by following the instructions here: https://www.serverlab.ca/tutorials/linux/web-servers-linux/how-to-configure-nginx-for-websockets/. But there is still one problem which stops it from functioning. I am seeing a 404 error for requests such as '/stomp/info?t=1589556727552', and there is no such error when running in development mode, the client gets back a JSON response as it should. Can't work out what the difference might be. Don't know whether this is relevant but this is running as an executable war, and it occurs with both Undertow and Tomcat as embedded servers.

zyro23 commented 4 years ago

please provide a sample app. regarding the nginx setup, im fine with a locally runnable docker-compose.yml and/or a k8s helm chart incorporating your sample app.

jonmor51 commented 4 years ago

OK, I'll see if I can reproduce something. I have to say, though, I feel it's probably some dumb error on my part, possibly to do with the reverse proxying. When I ssh into the remote server and use wget locally, wget http://localhost:8120/stomp/info?t=1589556727552, it works fine. Suggests the request is being treated differently depending on whether it's coming from outside or locally. Requests from a browser are obviously being treated as standard Grails requests, and failing because there is no /stomp controller with /info action. What is it which allows the requests to /stomp/* to bypass the normal Grails request handling mechanisms?

zyro23 commented 4 years ago

is https involved? at least the full nginx config would really help. also, which versions of grails and grails-spring-websocket?

jonmor51 commented 4 years ago

Forget about it for the moment, please! I have a strong suspicion I've wasted your time. I'll know very shortly...

jonmor51 commented 4 years ago

Still trying to track this down. I figured out one thing with my nginx.conf, but I'm now getting a whole bunch of 403 errors, such as https://[mysite]/stomp/607/te0g0ohi/xhr?t=1589563148249 403 (Forbidden). Thought I'd sorted this earlier with the advice from the article I mentioned but it's returned.

jonmor51 commented 4 years ago

Another error which is showing up when going via the nginx reverse proxy is this:

VM347 sockjs.min.js:2 Uncaught Error: Incompatibile SockJS! Main site uses: "1.3.0", the iframe: "1.0.0".

Any idea what that might mean?

zyro23 commented 4 years ago

too much moving parts. sample app please. thx,

jonmor51 commented 4 years ago

So, I've kind of moved on a little. I'm using this nginx.conf block: location /{ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_pass_header X-XSRF-TOKEN; proxy_pass http://127.0.0.1:8120/; proxy_set_header Origin "http://127.0.0.1:8120/"; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } This now means I don't get the WebSocket specific errors, but I still get a 403 error for this:

https://[mysite]/stomp/info?t=1589566688678

I suspect I need to configure a webSocketConfig class with less restrictive permissions, i.e.,setAllowedOrigins( "*" );

zyro23 commented 4 years ago

sample-app, please.

with https..

try adding this to grails-app/conf/application.yml:

server:
    use-forward-headers: true

nginx (inside the location block):

proxy_set_header X-Forwarded-Proto https;

this assumes you are using a browser as client, i.e. loading the js from the same domain you are targeting. if your client is something else, e.g. an app, you will also need to use setAllowedOrigins(...) as you mentioned.

jonmor51 commented 4 years ago

These suggested changes make it all work. Thanks! There are a couple of errors logged in the browser console which aren't showstoppers but which I can maybe address. I'll get back to you later.

zyro23 commented 4 years ago

glad you got it working. if there are other errors, please open separate issues with a sample app. thanks.