audreyt / ethercalc

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

Apache proxy #655

Open Tulkas59 opened 5 years ago

Tulkas59 commented 5 years ago

Hello,

I know other issues are already related to this topic but none has led me to a solution.

96

427

I want to access ethercalc through an apache proxy like this: https://\<domain>/ethercalc/. It seems that all but the "new" button works fine if do not use --basepath and configure a basic proxy. It's getting more complicated when I try to use basepath to fix the "new" button. My configuration files are the following:

systemd service:

[...]
[Service]
ExecStart=/usr/local/bin/ethercalc --basepath /ethercalc
[...]

apache (first try):

[...]
RedirectPermanent /ethercalc /ethercalc/
ProxyPass /ethercalc/ http://localhost:8000/ethercalc/
ProxyPassReverse /ethercalc/ http://localhost:8000/ethercalc/
RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/ec/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule <DocumentRoot>/ethercalc/(.*) ws://localhost:8000/ethercalc/$1 [P,L]
Alias /ethercalc/static <installation-path>/ethercalc/static
Alias /ethercalc/l10n   <installation-path>/ethercalc/l10n
Alias /ethercalc/images <installation-path>/ethercalc/images
[...]

apache (another try, same result):

[...]
<Location /ethercalc>
    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule <DocumentRoot>/ethercalc/(.*) ws://localhost:8000/ethercalc/$1 [P,L]
    RewriteCond %{HTTP:Upgrade} !=websocket [NC]
    RewriteRule <DocumentRoot>/ethercalc/(.*) http://localhost:8000/ethercalc/$1 [P,L]
    ProxyPassReverse http://localhost:8000
</Location>
[...]

The debug output of firefox:

Loading failed for the <script> with source “https://<domain>/ethercalc/static/ethercalc.js”.
Loading failed for the <script> with source “https://<domain>/ethercalc/socket.io/socket.io.js”.
Loading failed for the <script> with source “https://<domain>/ethercalc/zappa/zappa.js”.
Loading failed for the <script> with source “https://<domain>/ethercalc/player/broadcast.js”.
Loading failed for the <script> with source “https://<domain>/ethercalc/player/graph.js”.
Loading failed for the <script> with source “https://<domain>/ethercalc/player/main.js”.
ReferenceError: $ is not defined[Learn More]
Loading failed for the <script> with source “https://<domain>/ethercalc/static/makeup.js”.

I think it is related to the apache configuration but I failed to fix it.

Can you help me?

All the best,

eddyparkinson commented 5 years ago

Debug

Looks like it needs debugging. Suggest adding logs to this https://github.com/audreyt/ethercalc/blob/master/src/main.ls so you can see where the errors are.

Note this is main.ls file converted to JavaScript https://github.com/audreyt/ethercalc/blob/master/main.js You could edit it directly to debug.

basepath code

@hermannschwaerzlerUIBK inserted much of the basepath code on Jun 20, 2018 https://github.com/audreyt/ethercalc/commits/master/src/main.ls

Tulkas59 commented 5 years ago

I am not an expert in web-based technologies but I have the feeling that the nodeJS part assumes you access to ethercalc with https://\<domain>/\<basepath>/ while the html part assumes you access to it with https://\<domain>/, which is not consistent.

Example main.ls: line 66: @get "#BASEPATH/favicon-32x32.png": sendFile \favicon-32x32.png

Example index.html: line 58: <link rel="stylesheet" type="text/css" href="./static/socialcalc.css">

Using RewriteRule <DocumentRoot>/ethercalc/(.*) ws://localhost:8000/$1 [P,L] I have NodeJS errors (e.g. cannot find _start):

Using RewriteRule <DocumentRoot>/ethercalc/(.*) ws://localhost:8000/ethercalc/$1 [P,L] I get the following error: Loading failed for the <script> with source “https://<domain>/ethercalc/static/ethercalc.js”.

eddyparkinson commented 5 years ago

nodeJS part assumes you access to ethercalc with https:////

Yes, that makes sense.

while the html part assumes you access to it with https:///, which is not consistent.

Why do you think this? did you find an absolute path somewhere. "./static/socialcalc.css" is relative.

Tulkas59 commented 5 years ago

Indeed... This is stupid :-) I'll try to figure out why those files cannot be loaded.

Tulkas59 commented 5 years ago

Note also that the css file cannot be loaded/found (the welcome page is ugly), so this is not only related to the script files. Apache and ethercalc logs are empty.

emeric254 commented 4 years ago

HI, I encounter a similar error , apache is acting as a reverse proxy, proxying to ethercalc running as a docker

I messed around trying to rewrite URI but always got one problem. When i can access static files then I can't no more reach the server or the opposite

here is my docker command: docker run --name %p --log-driver none --network ethercalc-network --rm -e REDIS_HOST=ethercalc-redis -e REDIS_PORT=6379 -p 8000:8000 audreyt/ethercalc ethercalc --basepath=/ethercalc (gist here -> https://gist.github.com/emeric254/54395db8eda7e0f25c2c9deef9acda1e)

and my apache config: RedirectPermanent /ethercalc /ethercalc/ <Location "/ethercalc/"> ProxyPass http://localhost:8000/ ProxyPassReverse http://localhost:8000/ </Location>

Examples: https://my.domain/ethercalc/_start -> 404 https://my.domain/ethercalc/manifest.json -> works https://my.domain/ethercalc/start.html -> works https://my.domain/ethercalc/_new -> 404 https://my.domain/ethercalc/ethercalc/ -> almost work (all static files are missing) https://my.domain/ethercalc// -> send me on a new spreadsheet, wtf ? :thinking:

eddyparkinson commented 4 years ago

@emeric254

Looks like a problem with "--basepath=/ethercalc" Not sure if it is a bug or a settings issue.

So there is a pattern here:

Examples: https://my.domain/ethercalc/_start -> 404 https://my.domain/ethercalc/manifest.json -> works https://my.domain/ethercalc/start.html -> works https://my.domain/ethercalc/_new -> 404

All the 404s use basepath - the "works" don't use basepath.

Suggest you search the docs and issue for "basepath" to see if you can confirm you have the settings correct.

emeric254 commented 4 years ago

@eddyparkinson I may not have been explicit enough in my comment,

so without "--basepath=/ethercalc" https://my.domain/ethercalc/_start -> works https://my.domain/ethercalc/start.html -> does not work

and with "--basepath=/ethercalc" https://my.domain/ethercalc/_start -> does not work (seems to be https://my.domain/ethercalc/ethercalc/_start) https://my.domain/ethercalc/start.html -> works

I'm reverse proxy under "/ethercalc" so it sounds correct to use the basepath (that's what you find from reading the doc)

eddyparkinson commented 4 years ago

Bug or Setting issue

Have you tired using basepath without the Apache redirct. Looks like the redirect is adding an extra basepath

Basepath is used in: https://github.com/audreyt/ethercalc/blob/master/main.js

created by https://github.com/audreyt/ethercalc/blob/master/src/main.ls

Maybe if you edit main.js you can pin down the cause.

Tulkas59 commented 4 years ago

NB I never found a solution (I am now using a dedicated subdomain) so please keep me in touch !

joeried commented 4 years ago

I've reproduced this error (with and without proxy). It seems like all routes that are explicitly set take the basepath into account do work. What does not work, as far as I can tell, are the routes to static files (withtout explicitly set up routes).

Let's say I use /ethercals as basepath than I get the following result: http://hostname/ethercalc/ -> works as it should http://hostname/ethercalc/_start -> works as it should http://hostname/ethercalc/static/jszip.js -> does not work (but is reachable under http://hostname/static/jszip.js) http://hostname/ethercalc/player/graph.js -> does not work (but is reachable under http://hostname/player/graph.js)

I think there is simply missing a route with basepath for all static files that are loaded directly by path.

eddyparkinson commented 4 years ago

Fix

re-map these 6 folders in the proxy

/images -> /ethercalc/images
/player -> /ethercalc/player
/socket.io -> /ethercalc/socket.io /static/ -> /ethercalc/static/ /zappa -> /ethercalc/zappa
/l10n -> /ethercalc/l10n

e.g. map http://proxy-host/ethercalc/images/ to http://ethercalc-host/images

Note: static has several layers of sub folders

Also: set basepath

Edit: 1) joeried said this worked. see comment below, 2) added corrections as indicated by joeried

joebordes commented 4 years ago

@joeried I think that reference was for you.

joeried commented 4 years ago

@eddyparkinson I'm not sure if I understand your mapping notation correctly. I guess you want me to map http://proxy-host/ethercalc/images/ to http://ethercalc-host/images , right? If I map them in that direction (with socket.io instead of socker.io and an additional mapping for /ethercalc/l10n/) ethercalc seems to be working.

joeried commented 4 years ago

The workaround with the additional configuration works, but the above mentioned paths could still be modified to take the basepath into account.

admin-igpm commented 8 months ago

I posted another solution on https://github.com/audreyt/ethercalc/issues/427