overleaf / toolkit

GNU Affero General Public License v3.0
638 stars 153 forks source link

Loading of projects is disrupted when running behind a reverse proxy #78

Open rvollgraf opened 3 years ago

rvollgraf commented 3 years ago

Steps to Reproduce

  1. Running the overleaf docker listening on 127.0.0.1:8080 and exposing it via an Apache 2.4 reverse proxy at https://overleaf.my-own-server.com.
  2. Opening a project on the main landing page via the reverse proxy, (like https://overleaf.my-own-server.com/project/6165d8edd4574600848adecc

Expected Behaviour

Project should load without interruptions or significant delay, when using the reverse proxy.

Observed Behaviour

Loading any project hangs for about 20s showing
image Then, all of a sudden, that the project continues loading normally and everything seems to work fine. Via 127.0.0.1:8080 directly, the project loads immediately not having any delays.

Technical Info

The virtual host config file looks like this:

<VirtualHost *:443>
  ServerName overleaf.my-own-server.com
   ProxyRequests off
   ProxyPass / http://localhost:8080/
   ProxyPassReverse / http://localhost:8080/
   SSLCertificateFile /path/to/fullchain.pem
   SSLCertificateKeyFile /path/to/privkey.pem
</VirtualHost>

Analysis

The delay happens between loading

wss://overleaf.my-own-server.com/socket.io/1/websocket/a8xcva-aOsA4d_AE1r_v

and

https://overleaf.my-own-server.com/socket.io/1/xhr-polling/a8xcva-aOsA4d_AE1r_v?t=1634110147712

Apart from that, the DOM loading cascade shows no abnormalities (no other return codes than 200 and 206)

3nt3 commented 3 years ago

I use nginx so this is not a ready to use solution but I think you need to set more headers for it to work.

location / {
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_read_timeout 3m;
                proxy_send_timeout 3m;
}

Also I added

SHARELATEX_BEHIND_PROXY=true

in config/variables.env.

asvattha commented 2 years ago

I have exactly same problem. Any update on this?

Morasde commented 1 year ago

Its maybe a bit late but i think i managed to solve the issue. You need to set

   ProxyPass / http://localhost:8080/
   ProxyPassReverse / http://localhost:8080/

to

   ProxyPass / wss://subdomain.your-domain:your-port/   #Here you have to set subdomain.your-domain:your-port
   ProxyPassReverse / wss://subdomain.your-domain:your-port/   #Here you have to set subdomain.your-domain:your-port

At least thats what i did and now i get the expected behaviour.

fbotp commented 10 months ago

I use nginx so this is not a ready to use solution but I think you need to set more headers for it to work.

location / {
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_read_timeout 3m;
                proxy_send_timeout 3m;
}

Also I added

SHARELATEX_BEHIND_PROXY=true

in config/variables.env.

I use frp and nginx proxy, it really works for me! Thank you!!

temuccio commented 2 months ago

Hi, I used apache reverse proxy and had problems with opensocket.io Does nginx have the same problems or does it work fine?