audreyt / ethercalc

Node.js port of Multi-user SocialCalc
https://ethercalc.net
Other
2.97k stars 538 forks source link

apache proxypass not in root (ssl) #427

Open qnxor opened 8 years ago

qnxor commented 8 years ago

I used the apache conf example and created a proxypass to /ec/ rather than / (I have an SSL certificate tied to the hostname and I'd like ethercalc to use it too).

Most ethercalc functionality appears to work fine (I tried some quick editing with 2 simultaneous users and we can see each other's modifications) but looking in Chrome's debug I'm noticing that a websocket request fails and there is an XHR request to /zappa which fails (should normally be /ec/zappa):

WebSocket connection to 'wss://HOSTNAME/ec/socket.io/?EIO=2&transport=websocket&sid=1kfmQHfG6wWunJFXAAAR' failed: Error during WebSocket handshake: Invalid status line

and

vex.combined.min.js:2GET https://HOSTNAME/zappa/socket/__local/1kfmQHfG6wWunJFXAAAR 404 (Not Found)

The above errors do not show when I access :9000 directly or if I use a proxypass to / instead of /ec/.

I'm using Ubuntu 14.04.3 with redis and ethercalc was installed using npm install ethercalc and started using ethercalc --port 9000. Apache conf below.

Is there anything I'm doing wrong? Can the above be fixed for proxypass /ec/? Are those errors safe to ignore?

// minor bug: under my ubuntu I had to edit ethercalc and change #!/usr/bin/env node to #!/usr/bin/env nodejs or install nodejs-legacy since node is not an executable on the system.

The apache conf is:

<VirtualHost *:443>
        ServerName HOSTNAME
        ServerAdmin admin@HOSTNAME

        DocumentRoot /var/www/HOSTNAME

        <Directory /var/www/HOSTNAME/>
                Options -Indexes +FollowSymLinks +MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        RedirectPermanent /ec /ec/
        ProxyPass /ec/ http://127.0.0.1:9000/
        ProxyPassReverse /ec/ http://127.0.0.1:9000/

        RewriteEngine On
        RewriteCond %{REQUEST_URI}  ^/ec/socket.io [NC]
        RewriteCond %{QUERY_STRING} transport=websocket [NC]
        RewriteRule /(.*)           ws://localhost:9000/$1 [P,L]

        Alias /ec/static /var/www/node_modules/ethercalc/install/static
        Alias /ec/l10n /var/www/node_modules/ethercalc/install/l10n
        Alias /ec/images /var/www/node_modules/ethercalc/install/images

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLEngine on
        SSLCertificateKeyFile /etc/ssl/localcerts/HOSTNAME.key
        SSLCertificateFile /etc/ssl/localcerts/HOSTNAME.crt

        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                SSLOptions +StdEnvVars
        </Directory>
        BrowserMatch "MSIE [2-6]" \
                nokeepalive ssl-unclean-shutdown \
                downgrade-1.0 force-response-1.0
        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

</VirtualHost>
qnxor commented 8 years ago

Any word on this? What's the easiest fix?

I note that using --basepath /ec/ does not fix it. The above errors are still there.

admin-igpm commented 10 months ago

I tried the following setting on the proxy server:

    RedirectPermanent /ec /ec/
    ProxyPass /ec/ http://127.0.0.1:9000/
    ProxyPassReverse /ec/ http://127.0.0.1:9000/

Then accessing /ec/ works, and I also could create new spreadsheets. But the redirection from creating the spreadsheet went to the / location of the proxy server. eg. http://proxyserver/wavg3ghqyhr5 When I change the link manually in the browser to http://proxyserver/ec/wavg3ghqyhr5 everything seems to be fine.

So I replaced the BASEPATH with "/ec" in main.js whereever there was a call to the newRoom() function to create a new spreadsheet (all in all on 4 locations). eg.

this.get((ref$ = {}, ref$[BASEPATH + "/=_new"] = function(){ var room; room = newRoom(); return this.response.redirect(KEY ? "/ec" + "/=" + room + "/edit" // "/ec" instead of BASEPATH : "/ec" + "/=" + room); }, ref$));

This was easier than replacing all the other BASEPATH references And it seems to work.