How to set up an apache proxy for Meteor/SockJS and WebSocket?

后端 未结 5 1962
猫巷女王i
猫巷女王i 2020-12-05 12:31

I have an apache proxy for a meteor app and apache and meteor are on two separate machines. I need it that way as apache has to serve a lot of real websites and it wouldn\'t

5条回答
  •  渐次进展
    2020-12-05 13:10

    We use this for Apache and a SockJS app behind Apache. Apache is doing WebSocket proxy automatically, but you have to rewrite the scheme to ws otherwise it fallbacks to XHR. But only if the connection is a WebSocket handshake. Adding the following will fix your problem :) (note: change the localhost:3000 accordingly to your own backend url.

    RewriteEngine on
    RewriteCond %{HTTP:UPGRADE} ^websocket$ [NC]
    RewriteCond %{HTTP:CONNECTION} Upgrade [NC]
    RewriteRule .* ws://localhost:3000%{REQUEST_URI} [P]
    

提交回复
热议问题