SnapDrop / snapdrop

A Progressive Web App for local file sharing
https://snapdrop.net
GNU General Public License v3.0
18.43k stars 1.68k forks source link

Creating selfhosted with apache #302

Open jonathan-dejong opened 3 years ago

jonathan-dejong commented 3 years ago

Hi! I've got a digitalocean droplet where I thought I'd try and get snapdrop running selfhosted. It's running apache and are hosting ~5 sites already (really light traffic).

I've been trying to get snapdrop up and running on it using Ubuntu 18.04 + Apache but I am stuck on modifying the nginx config to apache which I think is the problem I have left.

What I've done

[Service] Type=simple User=www-data Group=www-data Restart=on-failure WorkingDirectory=/www/snapdrop.mydomain.dev/server ExecStart=/usr/bin/node index.js

[Install] WantedBy=multi-user.target

- Created a new apache site config trying to recreate the important parts from this nginx conf https://github.com/RobinLinus/snapdrop/issues/266

My snapdrop instance is seen, I can navigate to it on https etc. etc. but the websocket can't connect. 
Here's my apache config atm:
ServerAdmin me@mydomain.dev Servername snapdrop.mydomain.dev DocumentRoot /var/www/snapdrop.mydomain.dev/client/ Options indexes FollowSymLinks AllowOverride All Require all granted Order deny,allow Allow from all SSLEngine on SSLProxyEngine on ProxyRequests On ProxyPreserveHost On Include /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile /etc/letsencrypt/live/snapdrop.mydomain.dev/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/snapdrop.mydomain.dev/privkey.pem proxyPass https://snapdrop.mydomain.dev:3000 connectiontimeout=300 timeout=300 Keepalive=On proxyPassReverse https://snapdrop.mydomain.dev:3000 RequestHeader set Connection "upgrade" RequestHeader set Upgrade $http_upgrade RequestHeader set X-forwarded-for $remote_addr #REMOTE_ADDR ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined


and here's the log I get on the snapdrop PWA, the interesting part is the one with the websocket, the rest occurs for snapdrop.net as well. 
[snapdrop.mydomain.dev-1620627663639.log](https://github.com/RobinLinus/snapdrop/files/6449914/snapdrop.mydomain.dev-1620627663639.log)

I'd be super grateful for any help, I'm not great at servers but I'm learning as I go :) 
If I get this up and running I'll post a HOW TO guide back here.
jonathan-dejong commented 3 years ago

If I check out the request headers of the Webrtc a few seems set but it's not by my <Location> directive. If I change a value in there nothing changes.

Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8,sv;q=0.7
Cache-Control: no-cache
Connection: Upgrade
Host: snapdrop.mydomain.dev
Origin: https://snapdrop.mydomain.dev
Pragma: no-cache
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Key: 8y4DJ6ZhdImhLFF0mVoU/A==
Sec-WebSocket-Version: 13
Upgrade: websocket
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.86 Safari/537.36
quanltt commented 2 years ago

I use nodejs version and the following config works for me

Define pport 3001 RewriteEngine On RewriteCond %{HTTP:CONNECTION} Upgrade [NC] RewriteCond %{HTTP:Upgrade} =websocket [NC] RewriteRule /(.) ws://localhost:${pport}/$1 [P,L] RewriteCond %{HTTP:Upgrade} !=websocket [NC] RewriteRule /(.) http://localhost:${pport}/$1 [P,L] ProxyPassReverse / http://localhost:${pport}/

Tone866 commented 2 years ago

This is my apache-config, which is working, except the "X-Forwarded-For-Part" You also have to enable proxy_http, proxy, proxy_wstunnel with a2enmod.

RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /snapdrop/(.*) ws://localhost:8080/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /snapdrop/(.*) http://localhost:8080/$1 [P,L]

ProxyPass               /snapdrop/     http://localhost:8080/
ProxyPassReverse        /snapdrop/     http://localhost:8080/
ProxyPass               /snapdrop/     ws://localhost:8080/

<Proxy https://localhost:8080/>
    AllowOverride None
    Order allow,deny
    Allow from all
</Proxy>